对于一个小应用程序,我从脚本中打开一些窗口/选项卡。浏览器是打开窗口还是选项卡当然不在我手中。
但是,我保留了对新创建的 window
对象的引用,并且我确实从另一个窗口“远程”更改了它们的内容。这一切都发生在同一个 document.domain
下,因此不存在 xss 问题。
问题是,我无法可靠地聚焦
那些创建的窗口/选项卡。由于我正在为客户编写一个非常具体的应用程序,因此我仅将 Firefox 作为浏览器。当然,我的一个选择就是执行一个 remoteWindow.alert('foobar');
来将该窗口/选项卡放在前面,但这非常难看,不是吗。
我找到了这个答案How to focus window/tab like alert()?
据说,Firefox 有一个允许脚本焦点的选项。所以最后我的问题是,那个选项是什么?
我在 about:config
中搜索了“tabs”和“focus”,但没有找到任何相关内容。
如何配置?
最佳答案
以下内容似乎适用于 IE8 和 FF13:
<script type="text/javascript">
// Stupid script to force focus to an existing tab when the link is clicked.
// And yes, we do need to open it twice.
function openHelp(a) {
var tab = window.open(a.href, a.target);
tab.close();
tab = window.open(a.href, a.target);
return false;
}
</script>
<a href="help.html" target="help" onclick="return openHelp(this);">Help</a>
关于javascript - 焦点选项卡或窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8135188/