我正在打开一个带有窗口引用名称的子窗口。我想在每次其URL更改时捕获子窗口的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?