记得我在兴安得力实习要转正的时候,我领导象征性的给我出了一套测试题目,里面就有js闭包和页面刷新等题目。今天把好久以前的测试题目之一,js页面刷新的方法以及页面自动刷新跳转和返回上一页和下一页等方法总结一下,仅供你们参考!javascript
1、javascript页面刷新重载的方法:html
<a href="javascript:location.reload();">点击从新载入页面</a> <a href="javascript:history.go(0);">点击从新载入页面</a> <a href="javascript:location=location;">点击从新载入页面</a> <a href="javascript:location=location.href;">点击从新载入页面</a> <a href="javascript:location.replace(location);">点击从新载入页面</a> <a href="javascript:location.replace(location.href);">点击从新载入页面</a> <a href="javascript:location.assign(location);">点击从新载入页面</a> <a href="javascript:location.assign(location.href);">点击从新载入页面</a> <!--// 如下只支持ie --> <a href="javascript:document.URL=location.href;">点击从新载入页面</a> <a href="javascript:navigate(location);">点击从新载入页面</a> <a href="javascript:document.execCommand('Refresh');">点击从新载入页面</a> <!--// 以上只支持ie -->
2、html连接从新载入方法java
<!--// 如下不支持ie --> <a href="">点击从新载入页面</a> <!--// 以上不支持ie --> <a href="页面自己">点击从新载入页面</a>
3、自动刷新页面的方法闭包
<meta http-equiv="refresh" content="20"> //代码放在head中,每隔20秒钟刷新一次 <meta http-equiv="refresh" content="20;url=http://www.haorooms.com"> //20秒以后页面跳转到haorooms中,一般运用到404页面 //js自动刷新 function myrefresh() { window.location.reload(); } setTimeout('myrefresh()',1000); //指定1秒刷新一次
3、返回上一页和下一页的方法测试
history.go(-1)//返回上一页(括号中写-2表明返回上两页) history.back()//返回上一页 window.history.forward() //返回下一页