window.opener.focus() doesn't work

前端 未结 4 1947
旧时难觅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:19

    From the fine manual:

    Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.

    Emphasis mine. Calling focus() is just a request and the browser is free to ignore you and you should generally expect to be ignored. Consider what sorts of nefarious things you could get up to by switching focus to a tiny window while someone is typing if you need some reasons why a browser would ignore your request.

    If you need focus() to work for your application to work then you need to redesign your application so that it doesn't need to call focus().

提交回复
热议问题