2013-01-05 43 views
0

!! SOS !!iframe:後續點擊將新網址加載到新標籤

問題背景:我有一個文件,其中包含一些頁面標題和相應的URL。我正在動態讀取此文件,並生成一個表格,每行顯示(可點擊)標題。頁面上有一個iframe。我希望當用戶點擊其中一行時,相應的頁面應該加載到iframe中。這些網址可能屬於不同的網域。

主要問題:第一次點擊在iframe中完美打開相應的網址。但是,隨後的任何點擊(位於同一行或不同行中)都會在新窗口中打開url,而不是替換iframe中較早的url。

試着用搜索引擎它長,但現在看來,這個問題仍未解決(很多空的帖子沒有回覆:-()

請回復這個帖子,我將竭誠爲您提供更如果所需的信息/代碼

問候 P

PS:順便說,同樣的事情與此簡單的HTML代碼,兩個環節,一個iframe中發生的複製粘貼此HTML文件和嘗試。一個鏈接將加載iframe中的內容,另一個鏈接將重定向到一個新選項卡:x:x

<html> 
<table> 
<tr><td><a style="text-decoration:none; line-height: 150%; color:darkslategray;" href="http://www.usatoday.com/story/money/markets/2013/01/04/stocks-higher-bull-market-high/1810075/" target="main_frame">GM, Peugeot to Decide on Brazil Factory This Month, Veja Says <br>Bloomberg News &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2012-05-19</a></td></tr> 
<tr><td><a style="text-decoration:none; line-height: 150%; color:darkslategray;" href="http://www.reuters.com/article/2013/01/04/us-markets-stocks-idUSBRE8BG0D620130104" target="main_frame">GM, Peugeot no Decide on Brazil Factory This Month, Veja Says <br>Bloomberg News &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2012-05-20</a></td></tr> 
</table> 

<iframe name="main_frame" frameborder="0" marginheight="0" marginwidth="0" scrolling="yes" height="100%" width="100%" src=""></iframe> 

</html> 

在Chrome和Firefox上都測試過。

回答

0

其中一個網頁的改變其窗口的window.name,並通過目標窗口的名稱發生了,不是框架名稱...

+0

你有什麼建議,我怎麼能解決這個問題? – user1936037

+0

此外,如果一個網頁更改了window.name,那麼當我第一次點擊該鏈接時,它會在iframe中打開嗎? – user1936037

+0

第一次單擊鏈接時,更改名稱的網頁尚未加載。至於如何解決......我並不確定。你可以根據腳本定位設置進行各種黑客攻擊,這可能是最簡單的事情。這真的取決於你的其他限制。 –

1

解決它!

使用這兩個環節:https://developer.mozilla.org/en-US/docs/HTML/Element/iframeFirefox opens links targeted for iFrame in browser's new tab instead

和下面的一段代碼:

<html> 
<head> 
<script type="text/javascript"> 
function navigate(url) 
{ 
    var iframe = document.getElementsByTagName("iframe")[0]; 
    iframe.src = url; 
} 
</script> 
</head> 

<body> 
<table> 
<tr><td><a href="javascript:navigate('http://www.usatoday.com/story/money/markets/2013/01/04/stocks-higher-bull-market-high/1810075/')">Some title</a></td></tr> 
<tr><td><a href="javascript:navigate('http://www.reuters.com/article/2013/01/04/us-markets-stocks-idUSBRE8BG0D620130104')">Some Other title</a></td></tr> 
</table> 

<iframe name="main_frame" frameborder="0" marginheight="0" marginwidth="0" scrolling="yes" height="100%" width="100%" src=""></iframe> 

</body> 
</html> 
+0

謝謝,我一直在尋找這個解決方案! –

相關問題