Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 刷新Iframe时保留页面_Javascript_Html_Iframe - Fatal编程技术网

Javascript 刷新Iframe时保留页面

Javascript 刷新Iframe时保留页面,javascript,html,iframe,Javascript,Html,Iframe,我有3个div和1个Iframe。Iframe位于中。刷新时,它会返回到default.php。我想要的是在刷新Iframe时保留页面。例如,我单击link3并刷新它,它不应该返回到default.php。请帮忙 <div id="framecontentLeft"> <div class="innertube"> <a href="link1.php" target="contents">LINK1</a><br/> <a hr

我有3个div和1个Iframe。Iframe位于
中。刷新时,它会返回到default.php。我想要的是在刷新Iframe时保留页面。例如,我单击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>
尝试添加此

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


它将不强制进行缓存检查。

将事件侦听器添加到
event.preventDefault()
s的链接中,这样页面就不会使用单击链接的
href
更改和修改iframe的
src
属性。@ultraviol3tlux请原谅。但是我不知道怎么做。为什么我不能点击href?但是如何点击其他不在href中的页面?例如,在link1中有一个指向另一个页面的链接?
<head>
<meta http-Equiv="Cache-Control" Content="no-cache">
<meta http-Equiv="Pragma" Content="no-cache">
<meta http-Equiv="Expires" Content="0">
</head>