我有一个从我的 javascript 代码打开的窗口:
window.open('/Item/Article/' + item.ItemID(), 'ItemArticle',
'resizable=yes,scrollbars=yes,height=' + res.height + ',width=' + res.width + ',
left=0', null);
当满足某个条件时,我想更改该窗口的 html 地址,即将其重新加载到新位置。
如何为手动打开的窗口设置 ID 或 anchor ,以便我可以使用此 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'*/);
关于javascript - 如何为新打开的窗口设置ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17568669/