JavaScript open in a new window, not tab

前端 未结 15 1298
余生分开走
余生分开走 2020-11-21 22:18

I have a select box that calls window.open(url) when an item is selected. Firefox will open the page in a new tab by default. However, I would like the page t

15条回答
  •  悲哀的现实
    2020-11-21 22:44

    I had this same question but found a relatively simple solution to it.

    In JavaScript I was checking for window.opener !=null; to determine if the window was a pop up. If you're using some similar detection code to determine if the window you're site is being rendered in is a pop up you can easily "turn it off" when you want to open a "new" window using the new windows JavaScript.

    Just put this at the top of your page you want to always be a "new" window.

    
    

    I use this on the log in page of my site so users don't get pop up behavior if they use a pop up window to navigate to my site.

    You could even create a simple redirect page that does this and then moves to the URL you gave it. Something like,

    JavaScript on parent page:

    window.open("MyRedirect.html?URL="+URL, "_blank");
    

    And then by using a little javascript from here you can get the URL and redirect to it.

    JavaScript on Redirect Page:

     
    

提交回复
热议问题