我想打开一个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');
}
答案 0 :(得分:0)
试试这个:
var google;
function googleload()
{
google = window.open('http://www.google.com/');
// Dean Edwards/Matthias Miller/John Resig
/* for Mozilla/Opera9 */
if (google.document.addEventListener)
{
google.window.addEventListener("DOMContentLoaded", function(){
alert('Loading Completed');
}, false);
}
else
{
google.window.onload = function(){ //Add window.onload
alert('Loading Completed');
};
}
}
答案 1 :(得分:0)
如前所述,同样的原产地政策就是你的方式
如果我真的不得不
,我会尝试function popAndAlert(url) {
var w = window.open('','mywindow');
if (w) {
w.document.write('<body onload="opener.done()">'+
'<iframe style="width:100%;height:100%" src="'+url+'"></iframe></body>')
w.document.close();
}
}
function done() {
alert('loading completed');
}
在子页面中发出警报,更改
onload="opener.done()"
到
onload="alert('loading complete')"