简体   繁体   English

$window.focus() 不适用于 iOS Safari 中的现有选项卡

[英]$window.focus() doesn't work on existing tabs in iOS Safari

When I open a new window with var win = window.open("", "name") and then focus the window using win.focus() this works for the first time in iOS Safari.当我用var win = window.open("", "name")打开一个新的 window 然后使用win.focus()聚焦 window 这在 iOS Safari 中第一次起作用。

But when the existing window is referenced again by name using window.open I can't focus again in iOS Safari. In Chrome this works fine.但是,当使用 window.open 按名称再次引用现有的 window 时,我无法再次关注 iOS Safari。在 Chrome 中,这工作正常。

Is there any way how I can focus on an already existing tab just knowing the name?有什么办法让我只知道名称就可以专注于已经存在的选项卡?

I created a fiddle for testing: https://jsfiddle.net/szqnu38f/我创建了一个用于测试的小提琴: https://jsfiddle.net/szqnu38f/

This seems to be a bug within iOS Safari.这似乎是 iOS Safari 中的错误。

Generally, it is not possible to set the focus again on an existing named tab.通常,无法将焦点再次设置到现有的命名选项卡上。 This is also the case when a link with target set to a name is clicked again after the tab was opened --> see https://jsfiddle.net/g3bk1v5a/4/在打开选项卡后再次单击目标设置为名称的链接时也是这种情况 --> 请参阅https://jsfiddle.net/g3bk1v5a/4/

<a href="http://www.google.com" target="test">Test</a>

Therefore, I opened a bug report at Apple.因此,我在 Apple 开了一个错误报告。

Until the bug is fixed by Apple, you may use the following workaround:在 Apple 修复错误之前,您可以使用以下解决方法:

// replace win.focus() by:
win.close();
win = win.open("", "name");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM