在這裏工作是我的代碼:window.focus()的在Chrome
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(...)
劈,我想避免它。
頁面加載後,您不能使用'document.write'。如果你想測試,使用瀏覽器的控制檯。例如'console.log(「here」);' – epascarello
@epascarello這只是一個簡單的例子。兩者都會工作。而且 - 當然,我可以在頁面加載後執行'document.write' ...它將工作得很好.... – Neal
頁面加載後的document.write替換頁面內容,它將擦除什麼。你可以做到,但它會通過覆蓋它來破壞頁面! – epascarello