Javascript Bring window to front if already open in window.open?

后端 未结 8 661
别那么骄傲
别那么骄傲 2020-11-30 07:35

If you open a window like:

window.open (\"url\",\"winName\",\"location=0,width=300,height=214\");

If winName is already open i

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 07:47

    Update: This hasn't worked since Chrome (21+). The workaround is to close/reopen.

    The window.open() method returns an object that represents the new window. You just need to window.focus() it:

    var w = window.open ("url","winName","location=0,width=300,height=214");
    w.focus();
    

    Or simply:

    window.open("url","winName","location=0,width=300,height=214").focus();
    

提交回复
热议问题