window.focus() not working in Google Chrome

后端 未结 16 1761
余生分开走
余生分开走 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:21

    This works fine for me. Removed launching blank window from catch block, instead launching the url directly, which avoids user's confusion when he says blank window.

    windowHandle = window.open('', 'PrintInvoice', urlOptions);
    try {
        windowHandle.document.location.href = url;
    } catch (exc) {
        windowHandle.close();
        windowHandle = window.open(url, 'PrintInvoice', urlOptions);
    }
    windowHandle.focus();
    

提交回复
热议问题