最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to set an ID to a newly opened window? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

4 Answers 4

Reset to default 1

You 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 window

发布评论

评论列表(0)

  1. 暂无评论