window.focus() not working in Google Chrome

后端 未结 16 1729
余生分开走
余生分开走 2020-11-28 05:07

Just wondering if Google Chrome is going to support window.focus() at some point. When I mean support, I mean have it work. The call to it doesn\'t fail, it jus

16条回答
  •  攒了一身酷
    2020-11-28 05:25

    The only solution that currently works in Chrome is this code inside new window:

    $(".closeBtn").click( function(e) 
    {
        window.open("",window.opener.name);
        window.close();
    });
    

    Unfortunately the solution only works under two conditions:

    • window.opener has to have it's name set on document load (window.name="WhateverName";)
    • window.open() is called on user click

提交回复
热议问题