我正在启动一个带有窗口引用名称的子窗口。我想在每次更改时捕获子窗口的 URL。
var winRef;
var url='http://www.google.com';
if(winRef == null || winRef.closed)
{
winRef = window.open(url, "mywindow");
winRef.focus();
alert(winRef.location.href);
}
winRef.captureEvents(Event.CHANGE);
winRef.onchange=function(){
alert('change event triggered');
console.log(winRef.location.href);
}
我尝试使用事件 LOAD、CHANGE 来捕获窗口的位置变化。但 LOAD 和 CHANGE 事件仅触发一次。
我不想使用 setinterval 来检查 window.location.href 中的更改,因为它可能会导致性能问题。
有没有其他方法可以获取子窗口 URL?
您无法精确检测事件,但您可以采取解决方法并在 X 毫秒内检查 URL。
var self = this
var detectsUrl = setInterval(function(){
var a = winRef.document.createElement('a');
a.href = winRef.document.URL;
if (a.hostname == "www.myURL.com") {
winRef.close();
clearInterval(detectsUrl);
self.callback();
};
}, 1000); // Here we check every seconds
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)