I have a window which I open from my javascript code:
window.open('/Item/Article/' + item.ItemID(), 'ItemArticle',
'resizable=yes,scrollbars=yes,height=' + res.height + ',width=' + res.width + ',
left=0', null);
when a certain condition is met I want to change the html address of that window,ie reload it to a new location.
how can I set an ID or an anchor to the window which I open manually, so that I can use this ID to reload that window with a new location.
I have a window which I open from my javascript code:
window.open('/Item/Article/' + item.ItemID(), 'ItemArticle',
'resizable=yes,scrollbars=yes,height=' + res.height + ',width=' + res.width + ',
left=0', null);
when a certain condition is met I want to change the html address of that window,ie reload it to a new location.
how can I set an ID or an anchor to the window which I open manually, so that I can use this ID to reload that window with a new location.
Share Improve this question edited Jul 10, 2013 at 10:49 Amit 15.4k8 gold badges49 silver badges69 bronze badges asked Jul 10, 2013 at 10:47 Farhad-TaranFarhad-Taran 6,55017 gold badges69 silver badges129 bronze badges 1-
try remove
ItemArticle
from code – Amit Commented Jul 10, 2013 at 10:49
4 Answers
Reset to default 1You have the possibility to 1) have a reference to your window and 2) state the name when using window.open()
.
var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);
You can modify your window by choosing the same window name (the second argument).
var myWindow = window.open("http://google.","myWindow");
// opens SO in the same window
window.open("http://stackoverflow.","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();
So in your case, the following line should work:
window.open('newURL','ItemArticle'/* optionally: ,'Parameters'*/);
You can store the window in a variable and then control it just as you would normally control a window object.
The following code will open a new window, and after 4 seconds, reload to a new location.
myWindow=window.open('','','width=200,height=100');
myWindow.focus();
setTimeout(function(){
myWindow.document.location = "http://www.google.";
}, 4000);
If you want to update the URL of Window B from window A, you can do window.open
and provide the same name as the second argument. This will simply "re-open" the already open window, and redirect it to the new URL.
window.open('http://www.google.','googleWindow');
window.open('http://www.stackoverflow.','googleWindow');
Above code will open a window at Google, and instantly redirect it to Stack Overflow
Uncertain if this automatically focuses the window however!
You can use below way to access function in parent windows from where the child windows was opened.
window.opener.ParentWindows(); //Here ParentWindows() is userdefined function coded by me in parent windo
w