簡體   English   中英

刷新iframe時保留頁面

[英]Retain the page when Refresh the Iframe

我有3個div和1個iframe。 Iframe位於<div id="maincontent"> 刷新時,它會返回到default.php。 我想要的是在刷新iframe時保留頁面。 對於ie,我單擊link3並刷新它,它不應該回到default.php。 請幫忙。

<div id="framecontentLeft">
<div class="innertube">
<a href="link1.php" target="contents">LINK1</a><br/>
<a href="link2.php" target="contents">LINK2</a><br/>
<a href="link3.php" target="contents">LINK3</a><br/>
<a href="link4.php" target="contents">LINK4</a><br/>
</div>
</div>

<div id="framecontentTop">
<div class="innertube">

<img src="images/header.jpg"/> 

</div>
</div>


<div id="maincontent">
<div class="innertube">

<iframe name="contents" src="default.php" id="iframe"></iframe>

</div>
</div>

如果您使用的是jQuery,它將有點像這樣:

$('a').on('click', function(e){

    // This stops the page from refreshing
    e.preventDefault();

    // This passes the target page from the link into the iframe
    $('iframe').attr('src', $(this).attr('href'));

});

希望有幫助!

如下所示修改html

<div id="framecontentLeft">
<div class="innertube">
<a onclick="SetPage('link1.php','contents');return false;">LINK1</a><br/>
<a onclick="SetPage('link2.php','contents');return false;">LINK2</a><br/>
<a onclick="SetPage('link3.php','contents');return false;">LINK3</a><br/>
<a onclick="SetPage('link4.php','contents');return false;">LINK4</a><br/>
</div>
</div>

在腳本標簽中添加以下javascript

function SetPage(linkUrl, target) {
  document.getElementById(target).src = linkUrl;
}

嘗試添加此...

<head>
<meta http-Equiv="Cache-Control" Content="no-cache">
<meta http-Equiv="Pragma" Content="no-cache">
<meta http-Equiv="Expires" Content="0">
</head>

它將不強制執行任何緩存檢查。

暫無
暫無

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

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