简体   繁体   中英

How to check window.open() opening same page twice

I want to open a page with javascript window.open() and i want to check if that page is opened in a window before just bring it to front and if that page not opened before open it with a new window.

I am making a music player and i want to add it to pages in my site. when a user click "open player" button it will open the player popup window. but it was opened by the user before when button clicked it would be bring that opened window rather than opening a new window.

Any javascript or jquery solutions are there?

This is the function i using to open new window.

function popUp() {
        window.open("popup_player.php", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400",true);
    }

If you give the window a name (the second argument), on the second call window.open will just focus the window rather than opening a new one. So:

window.open(yourUrl, "aWindowName");

The browser may reload the window on the second open. If you don't want that, you can use a blank URL:

var wnd = window.open("", "aWindowName");
if (!wnd.location.hostname) {
    wnd.location = yourUrl;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM