2011-03-06 53 views
0

我是新來的人,想知道如何在一個頁面上刷新2個不同的iframe。如何使用html/js刷新帶有一個鏈接/按鈕的2個iframe

我在google上使用getElemenById發現了一些東西。但它必須在Firefox中工作,並且Firefox在Id中有一些問題。

在此先感謝。

<form action="managecartform.html" onclick="deleteAllCookies();"><button type="submit" >Empty cart</button></form> 
+0

請更新您的html使用實際的html,並指定何時要重新加載iframe,以及是否要將表單提交到當前頁 – mplungjan 2011-03-07 10:46:40

回答

0

你的表單與iframe有什麼關係?

你的意思是?將managecartform加載到一個框架中並重新加載另一個框架?

<form action="managecartform.html" target="iframe1" 
onsubmit="deleteAllCookies(); window.frames[0].location.reload(1);"> 
<input type="submit" value="Empty cart"/> 
</form> 
<iframe name="iframe0"></iframe> 
<iframe name="iframe1"></iframe> 
0

firefox沒有id問題 - 99%的時間是因爲你有一個缺少的id或者你重複了一個id。

ids在整個文檔中必須是唯一的。

到,雖然回答你的問題:

<iframe id="frame1"></iframe> 
<iframe id="frame2"></iframe> 

<input type="button" onclick="refreshFrames()" value="refresh frames" /> 

<script type="text/javascript"> 
    function refreshFrames(){ 
      frame1 = document.getElementById('frame1'); 
      frame2 = document.getElementById('frame2'); 
      if(frame1.contentDocument){ 
       frame1.contentDocument.location.reload(true); 
       frame2.contentDocument.location.reload(true); 
      } else { 
       frame1.contentWindow.location.reload(true); 
       frame2.contentWindow.location.reload(true); 
      } 
    } 
</script> 

(使用IE,你可能需要使用的,而不是contentDocument取決於IE的版本你想支持contentWindow)

+0

讓我重新說明第一部分:在10年來,我一直在進行客戶端開發,我從來沒有遇到過一個問題,其中document.getElementById()在firefox EXCEPT中無法正常工作時,當我要麼丟失我元素的d屬性,或者有兩個具有相同id屬性的項目。 – tkone 2011-03-06 18:17:57

+0

我試過你的代碼,但是當我從Firefox打開錯誤控制檯時,我收到消息:frame1 = null。 iframe被編碼爲: