0

I am trying to open a url in a new tab with the below code, but can't able to do so

partial_url = '/products/compare/?ids=f25353f4e8f2,598f4166e2d9,39c17d76-133e-4a86-bf39-d4d5e600349a&fis=1,2,3,4,5,6,8,10'

final_url = window.location.host + partial_url + '&new_html=true';

var win = window.open(final_url, '_blank');
win.focus();

The above code was opening a new tab but with about:blank in the address bar, but was not opening my url, so what's wrong in the above code ?

Note: 

final_url = 'http://localhost:8000/products/compare/?ids=f25353f4e8f2,598f4166e2d9,d4d5e600349a&fis=1,2,3,4,5,6,8,10&new_html=true'
2
  • 1
    Can you console "final_url" and show output? Commented Aug 24, 2016 at 9:06
  • 1
    Looks weird, your same code is working fine for me. Have you type="text/javascript" attribute in your script tag? also try to define "var final_url" once. Commented Aug 24, 2016 at 9:15

2 Answers 2

1

Try this: by default window.open will open in a new tab

var win = window.open(final_url);

It works for me.

Sign up to request clarification or add additional context in comments.

Comments

0

Remove window.location.host try it

final_url = partial_url + '&new_html=true';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.