JavaScript open in a new window, not tab

前端 未结 15 1579
余生分开走
余生分开走 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 23:05

    Answered here. But posting it again for reference.

    window.open() will not open in new tab if it is not happening on actual click event. In the example given the url is being opened on actual click event. This will work provided user has appropriate settings in the browser.

    Link
    
    

    Similarly, if you are trying to do an ajax call within the click function and want to open a window on success, ensure you are doing the ajax call with async : false option set.

提交回复
热议问题