Javascript 更改已打开的弹出窗口的 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10774211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
change url of already opened popup
提问by Sushant
Is it possible to change the url of the popup.
是否可以更改弹出窗口的网址。
Assume I open a popup:
假设我打开一个弹出窗口:
function pop1(){
window.open('http://google.com','wind1');
}
Can the url of the popup window 'wind1' be changed to say 'http://msn.com'. Something with location.href or any other solution.
可以将弹出窗口“wind1”的网址更改为“http://msn.com”。带有 location.href 或任何其他解决方案的东西。
回答by Denys Séguret
var w1 = window.open('http://www.canop.org','wind1');
w1.location.href='http://www.google.com';
回答by hakim-sina
in the new popup window use this :
在新的弹出窗口中使用这个:
$(document).ready(function(){ window.parent.location="http://www.google.com" })
$(document).ready(function(){ window.parent.location="http://www.google.com" })
回答by Sergio Abreu
For me, as I was changing just the end of the url (parameters part), I used a little trick: Loading a different url before using the new similar url. I chose to use 'about:blank', but any website url could be used.
对我来说,因为我只是在更改 url 的末尾(参数部分),所以我使用了一个小技巧:在使用新的类似 url 之前加载不同的 url。我选择使用“about:blank”,但可以使用任何网站 url。
self.location = "about:blank";
self.location = desired_url;
//this code works fine both in Mozilla Firefox as in Chrome
Notice that just location = site; does the same as location.href = site.
I use location.href only to READ the current url.
请注意,仅 location = site; 与 location.href = site 相同。
我只使用 location.href 来读取当前的 url。