我想打开一个窗口window.open
并为其附加一个功能onload
。例如,当子页面加载完成(仅 DOM)时,浏览器会在子页面中显示警报。此代码不起作用::
var google;
function google(){
google = window.open('http://www.google.com/');
// Dean Edwards/Matthias Miller/John Resig
/* for Mozilla/Opera9 */
if (google.document.addEventListener){
google.document.addEventListener("DOMContentLoaded", pageLoaded, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
google.document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = google.document.getElementById("__ie_onload");
script.onreadystatechange = function(){
if (this.readyState == "complete") {
pageLoaded(); // call the onload handler
}
};
/*@end @*/
/* for Safari */
if (/WebKit/i.test(navigator.userAgent)){ // sniff
var _timer = setInterval(function(){
if (/loaded|complete/.test(google.document.readyState)) {
pageLoaded(); // call the onload handler
}
}, 10);
}
google.onload = pageLoaded;
}
function pageLoaded(){
alert('Loading Completed');
}