1 html javascript firefox popup
我知道FF4不允许使用,window.blur()除非在FF配置中启用"升高或降低窗口"设置.它简单地忽略了这个事件.
我知道有些网站仍设法打开一个弹出窗口,并将焦点保持在当前窗口,即使此设置已关闭.他们是如何做到这一点的?
另外,我不明白为什么.blur()和.focus()在两个页面都驻留在同一个域时不起作用.根据http://support.mozilla.com/en-US/questions/806756#answer-167267,这应该工作.
这在Firefox和Chrome中适用于默认设置(JSFiddle):
function popUnder(url, width, height) {
var popUnderWin, nav = navigator.userAgent,
isGecko = /rv:[2-9]/.exec(nav),
hackString;
hackString = nav.indexOf('Chrome') > -1 ? "scrollbar=yes" : "toolbar=0,statusbar=1,resizable=1,scrollbars=0,menubar=0,location=1,directories=0";
popUnderWin = window.open("about:blank", "title", hackString + ",height=" + height + ",width=" + width);
if (isGecko) {
popUnderWin.window.open("about:blank").close();
}
popUnderWin.document.location.href = url;
setTimeout(window.focus);
window.focus();
popUnderWin.blur();
}
document.getElementById("asd").addEventListener("click", function() {
popUnder("http://www.google.com", 1024, 768);
}, false);
Run Code Online (Sandbox Code Playgroud)
<div id="asd">click here</div>
Run Code Online (Sandbox Code Playgroud)
没有hacky额外的参数window.open,我没有设法让它工作,所以他们有一些东西.