簡體   English   中英

在 iframe 中刷新頁面

[英]Refresh page within an iframe

我有一個應用程序(facebook 畫布應用程序,facebook 在 iframe 中顯示該應用程序)

當用戶單擊鏈接時,我希望能夠刷新頁面。

我用來刷新頁面的代碼如下:

window.location.reload(true);

使用 firefox 這工作正常,它只刷新 iframe 中的當前頁面。 所以我很高興。

使用 IE,整個頁面都會被刷新,這會導致用戶轉到應用程序的開頭。

我怎樣才能避免這種情況?

我只想刷新當前頁面而不是當前 url。

apps.facebook.com/foo/

是應用程序 URL,在 URL 內用戶點擊鏈接轉到頁面,然后在該頁面內我需要刷新該頁面以更新一些計數器。 但是當我刷新整個請求時,會轉到apps.facebook.com/foo/

有任何想法嗎?

var oiframe = document.getElementById('myiframe');

oiframe.contentWindow.location.reload(true);

你可以使用window.location.href = window.location.href

http://www.hyperorg.com/blogger/2007/03/24/refresh-an-iframe-in-ie-anyone/所述

HTML

<div id="wrapper"></div>

Javascript

function reload () {
    var fr=document.getElementById('tehframe');
    if(fr!=null) document.getElementById("wrapper").removeChild(fr);
    var iframehtml="<iframe id='tehframe' src=…></iframe>";
    document.getElementById("wrapper").innerHTML=iframehtml;
}

然后只要在開始時和任何你想加載它的時候調用reload()即可。

您可以更改 iframe 的 url 並通過向 url 添加無意義的參數來導致刷新,例如 foo 變為 foo?bar

你可以使用這個技巧:

  <button onclick="window.parent.location = document.referrer">
    Reload
  </button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM