js怎么只刷新当前页面一次
投稿:yin
Javascript刷新页面的几种方法:location.reload()、location.replace(location)、history.go(0)、location=location、location.assign(location)、document.execCommand('Refresh')、window.navigate(location)、document.URL=location.href,js怎么只刷新当前页面一次呢
Javascript刷新页面的几种方法:location.reload()、location.replace(location)、history.go(0)、location=location、location.assign(location)、document.execCommand('Refresh')、window.navigate(location)、document.URL=location.href。js怎么只刷新当前页面一次呢?本文介绍两种方法。
方法一:把当前页面的地址赋给变量 url
<script>
function reurl(){
url = location.href; //把当前页面的地址赋给变量 url
var times = url.split("?"); //分切变量 url 分隔符号为 "?"
if(times[1] != 1){ //如果?后的值不等于1表示没有刷新
url += "?1"; //把变量 url 的值加入 ?1
self.location.replace(url); //刷新页面
}
}
onload=reurls
</script> 方法二:使用reload 方法,强迫浏览器刷新当前页面一次。
<script>
$(document).ready(function () {
if(location.href.indexOf("#reloaded")==-1){
location.href=location.href+"#reloaded";
location.reload();
}
})
</script> 原理总结
就是充分利用地址栏可带参数的选项,用脚本来取得页面间的传递参数,判断当前网址中是否有参数进行网址跳转。
到此这篇关于js怎么只刷新当前页面一次的文章就介绍到这了,更多相关js刷新当前页面一次内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
