簡體   English   中英

刷新后是否可以保留iframe網址?

[英]If it possible to retain iframe url after refresh?

我想保留當前頁面,但是每次刷新iframe時,都要回到默認頁面url src="app.php" 例如,我在pr.php上,而我不小心刷新了頁面,我想繼續瀏覽該頁面。 如果可以的話

<a href="app.php" target="contents">APP</a><br/>
<a href="rfq.php" target="contents">RFQ</a><br/>
<a href="pr.php" target="contents">PR</a><br/>
<a href="addapp.php" target="name" onclick="modalWin(); return false;">Add APP</a><br/>
<a href="livesearch/index.php" target="contents">SEARCH</a><br/>

    <iframe name="contents" src="app.php" frameborder="0"  id="iframe" 
    frameborder="0" style="moz-overflow:hidden;moz-overflow-x:hidden;moz-overflow-y:hidden;height:100%;width:100%;position:absolute;top:0px;left:0px;right:0px;bottom:0px" height="100%" width="100%"> </iframe>

您可以使用html5 localStorage保存iframe的當前網址,然后刷新頁面嘗試加載它,如果未定義則嘗試加載初始頁面。 您的iframe的標簽聲明中不得包含src屬性,您將使用jquery對其進行設置。 我已經大致了解了您的需求,希望它能起作用

$(document).ready(function() {
    currentLocation = localStorage.prevUrl || 'yourInitialSrc';

    $('#iframe').attr('src', currentLocation);
    $('#iframe').load(function() {
        localStorage.prevUrl = $(this)[0].contentWindow.location.href;
    })
})

當您的iframe加載頁面時,會觸發iframe加載事件。 因此,在iframe中,如果您轉到另一個鏈接,則會觸發加載事件,然后將您現在的網址保存在瀏覽器中。

但請嘗試不惜一切代價避免使用iframe。 並注意如何操作本地存儲...

暫無
暫無

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

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