简体   繁体   English

刷新iframe时保留页面

[英]Retain the page when Refresh the Iframe

I have an 3 divs and 1 Iframe. 我有3个div和1个iframe。 The Iframe is in <div id="maincontent"> . Iframe位于<div id="maincontent"> When refresh it goes back to the default.php. 刷新时,它会返回到default.php。 What I want to is to retain the page when refresh the Iframe. 我想要的是在刷新iframe时保留页面。 For ie I click link3 and refresh it, it should not back to the default.php. 对于ie,我单击link3并刷新它,它不应该回到default.php。 Any help please. 请帮忙。

<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>

If you were using jQuery, it'd go a little something like this: 如果您使用的是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'));

});

Hope that helps! 希望有帮助!

Modify html as shown below 如下所示修改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>

Add following javascript in script tag 在脚本标签中添加以下javascript

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

Try adding this... 尝试添加此...

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

It will force no cache checks. 它将不强制执行任何缓存检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM