通过 iframe 元素的 location 属性对页面进行刷新,比如 the_iframe.location.reload()
同域下可以这样实现<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
<iframe id="test" frameborder=0 width=250 height=250 marginheight=0 marginwidth=0 scrolling=no src="a.html"></iframe>
<script type="text/javascript">
// 兼容IE事件绑定
function addEvent(elem, eventName, func) {
if (!elem) return
if (window.addEventListener) {
elem.addEventListener(eventName, func, false)
} else if (window.attachEvent) {
elem.attachEvent('on' + eventName, func)
}
}
function onKeyUp(e) {
e = e || window.event
var iframe = document.getElementById('test')
var keyCode = e.keyCode
if (keyCode === 13) {
iframe.contentWindow.location.reload()
}
}
addEvent(document.body, 'keyup', onKeyUp)
</script>
</body>
</html>
慎用 iframe.
子页面直接 用div, jquery语法来自动刷新子页面, 不会造成任何破坏:
<div id='childpage'></div><script>
setInterval(function(){
$("#childpage").load("jc2.php")
}, 10000)
</script>