这是我的代码:
var myWindow = window.open('','zzz','width=600,height=700');
myWindow.document.write('test');
myWindow.blur();
myWindow.focus();
window.onfocus=function(){
this.document.write('<br />Focused!');
}
var w = window;
myWindow.onfocus=function(){
this.blur();
this.document.write('<br />Focusing on main window!');
w.focus();
};
myWindow.focus();
这是小提琴:http: //jsfiddle.net/maniator/nMGNS/
当弹出窗口聚焦时,它应该在弹出窗口上打印Focusing on main window!
,然后聚焦在主窗口上并Focused!
在那里打印。
但事实并非如此。
以下是有关我的浏览器的信息:
Google Chrome 22.0.1229.79 (Official Build 158531) m
OS Windows
WebKit 537.4 (@129177)
JavaScript V8 3.12.19.11
Flash 11.3.31.331
User Agent Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
旁白:
我知道alert(...)
黑客攻击,我想避免它。</p>