-1

I have a select dropdown list that contains the names of sites. When you select a name I want a new page, or tab, to open in the user's browser that contains the selected page. I don't want to just do a window.location.href=new page and put the new page in the existing window.

I could do a window.open(url), where url is what was selected from the dropdown, but Safari blocks that as a popup.

Clicking on the name in the dropdown needs to have the save effect as clicking the link

          <a href="/chosen_site" target="_blank">View site</a>

Does anyone have any thoughts on how I can do this?

Thanks

Steve
  • 4,534
  • 9
  • 52
  • 110

2 Answers2

0

What you're trying to do is called "open popup", so "popup blocker" of course blocks it, as it very annoying for 99% of users (the same as open any link when user just chooses item in selectbox)

so the answer - do not do this, or do this only for youself by allowing particular site to open popups

of course you can try some hack like appending temporary <A href="" target="_blank"...> into html and emulating click on it, check Simulate Click Javascript

Community
  • 1
  • 1
Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57
0

Bad news: If you want it to be opened in a new tab or a new window (keep in mind that whether a new tab or window is created, is decided by the browser and you can not control it), I think you can not do this without window.open(). Good news is that by using:

window.open(
  'http://yoursite.com',
  '_blank'
);

will achieve what you need.

If you do not need to open in a new window, then document.location.href = "http://yoursite.com" would work.

You can achieve what you need by doing this: check in fiddle

<select>
    <option value="">Nothing</option>
    <option value="http://stackoverflow.com/users/1090562/">me on SO </option>
    <option value="google.com"> google.com </option>
</select>

$("select").change(function(){
    var url = $(this).val();
    if (url){
        window.open(url, '_blank');
    }
})
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753