Window.open only if the window is not open

前端 未结 3 1417
予麋鹿
予麋鹿 2021-01-18 02:14

I have a link on my site that opens a new window to a page that plays a very long audio file. My current script works fine to open the page and not refresh if the link is cl

3条回答
  •  天涯浪人
    2021-01-18 02:32

    Thanks to Stan and http://ektaraval.blogspot.ca/2011/05/how-to-set-focus-to-child-window.html

    My solution creates a breakout pop-up mp3 player that remains active site wide and only refreshes if the window is not open prior to clicking the link button

    function OpenWindow(){
        var targetWin = window.open('','winPop', 'sample-options');
        if(targetWin.location == 'about:blank'){
            //create new
            targetWin.location.href = 'http://site/megaplayer';
            targetWin.focus();
        } else {
            //give it focus (in case it got burried)
            targetWin.focus();
        } 
    }
    

提交回复
热议问题