我正在尝试使用window.blur()打开一个不聚焦它的窗口(或者聚焦和不聚焦非常快,所以看起来它没有聚焦)。
但是好像不行,有没有其他办法?
我的尝试:
模糊测试.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script>
<![CDATA[
function onkeypress(event) {
// for this sample don't matter which key is pressed
open('second.xul','SecondWindow','chrome, width=400, height=300');
}
addEventListener("keypress", onkeypress, false);
]]>
</script>
<label value="MAIN WINDOW"/>
</window>
第二个.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window width="400" height="300"
onload="blur();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<label value="SECOND" />
</window>
观察。我们可以考虑在打开第二个窗口后使用 setTimeout(window.focus, 1) 将焦点调回我的窗口。但我需要第二个窗口来处理焦点。完美的场景是,如果第二个窗口永远无法获得焦点,只需打开/恢复窗口而不获得焦点。