window.opener.focus() doesn't work

前端 未结 4 1954
旧时难觅i
旧时难觅i 2020-12-04 01:55

I can\'t seem to get this to work.

In response to a click, window A opens window B (which then has focus). Then, in response to a click on B, the window calls

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 02:00

    Workaround In main window added script function:

        function here() {
            alert('Welcome Back')  // seems needed to wake up document
            window.focus()
        }
    

    In opened window invoke script function:

        function HomeTab()  {
            O = window.opener;
            if (O)
                if (O.closed)   alert('Home page has been closed')
                else    O.here()
            else alert('This tab has no home page')
        }
    

    Works widely differently in different browsers Some will have the parent tab blink Some mark the parent tab, and you have to notice it Some you have to click on home tab the first time and you can then give it permission to go directly to home tab without a confirm box.

提交回复
热议问题