我有一个iframe,其src文件(如下所示)包含一个使用_self target的表单。该操作返回文本字符串。提交后,如果鼠标离开表单或用户键入ESC,我想用原始内容重新加载iframe。
我无法让iframe重置自己。任何帮助赞赏。这是'主人' html文件:
<html>
<head>
<title>iframe test</title>
<script type="text/javascript" src="../jquery-1.11.1.js"></script>
<script>
function foo(e){
$('iframe.popup').css('display','block');
$(e.target).css('z-index','10');
}
$(document).ready(function(){
var popup = $(document).find(".popup");
popup[0].origSrc = popup[0].src; // save orignal content of iframe
$(document).keyup(function(e) {
if ( //e.keyCode == 13 || // enter
e.keyCode == 27) { // esc
$(document).find(".popup").hide();
}
});
$(".floatbar").click(function(e){
if (e.target.className == "floatbar"){
e.preventDefault();
}
else {
return true;
}
popup = $(this).find(".popup");
popup.empty();
popup.load(popup[0].origSrc);
popup.show();//fadeIn("slow");
popup.mouseleave(function(e){
//$(this).fadeOut("fast");
$(this).hide();
$(this).empty();
});
popup.keydown(function(e){
if ( e.keyCode == 27 ){
$(this).hide();
$(this).empty();
}
});
});
});
</script>
<style>
.popup {
position:absolute;
border:1em;
top:0px;
font-size: 2.0em;
display:none;
text-decoration: none;
z-index: 5;
}
iframe.login {
background: darkblue;
width: 300%;
min-height:400px;
}
form {
color: white;
list-style-type: none;
}
</style>
</head>
<body>
<a class="floatbar" href="#">Some text
<iframe class="popup login" src="register.close.html"></iframe>
</a>
</body> </html>
文件&#39; register.close.html&#39;:
<html>
<head>
</head>
<body>
<form name="registration" action="../php/register.php" method="post"
accept-charset="utf-8" target="_self" >
<div>
<p><label for="submit"> Hi</label>
<input type="submit" name="submit" id="submit" value="Register" >
</p>
</div>
</form>
</body> </html>
再次感谢。
答案 0 :(得分:0)
要重新加载iframe,我只需使用以下代码即可。
$("#iframe").attr("src", $("#iframe").attr("src"));
所有这一切都将iframe的src
属性设置为自身。这导致它重新加载。