我有一个从我的JavaScript代码打开的窗口:
window.open('/Item/Article/' + item.ItemID(), 'ItemArticle',
'resizable=yes,scrollbars=yes,height=' + res.height + ',width=' + res.width + ',
left=0', null);
当满足特定条件时,我想更改该窗口的html地址,即将其重新加载到新位置。
如何为手动打开的窗口设置ID或锚点,以便可以使用此ID重新为该窗口加载新位置。
最佳答案
您可以1)引用窗口,2)使用window.open()
时声明名称。
var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);
您可以通过选择相同的窗口名称(第二个参数)来修改窗口。
var myWindow = window.open("http://google.com","myWindow");
// opens SO in the same window
window.open("http://stackoverflow.com","myWindow");
// the following will only work if it's the same domain, else subject to SOP -
// so in the case of initially opening it with google, this won't work!
myWindow.document.location.href = "/example/test.html";
// closes your window
myWindow.close();
因此,在您的情况下,以下行应该有效:
window.open('newURL','ItemArticle'/* optionally: ,'Parameters'*/);