2012-05-27 24 views
16

是否可以更改彈出窗口的網址。更改已打開彈出窗口的URL

假設我打開一個彈出:

function pop1(){ 
    window.open('http://google.com','wind1'); 
} 

可以彈出窗口「wind1」的網址改爲說「http://msn.com」。與location.href或任何其他解決方案。

回答

25
var w1 = window.open('http://www.canop.org','wind1'); 

w1.location.href='http://www.google.com'; 
+0

附錄:https://developer.mozilla.org/en-US/docs/Web/API/Window/open – DanFromGermany

2
在新彈出的窗口中使用

這樣的:

$(文件)。就緒(函數(){ window.parent.location = 「http://www.google.com」 })

+2

他想改變彈出窗口的內容,而不是開啓者。 –

+0

你告訴我相反。需要時會派上用場。 – Sushant

2

對於我來說,因爲我改變URL(參數部分剛結束),我用了一個小竅門: 使用新的類似的URL之前加載不同的URL。 我選擇使用'about:blank',但任何網站的網址都可以使用。

self.location = "about:blank"; 
self.location = desired_url; 

//this code works fine both in Mozilla Firefox as in Chrome 

請注意,只是位置=站點;與location.href = site相同。
我只使用location.href來讀取當前的url。