js 如何判断页面是否刷新???
//check for Navigation Timing API support
if (window.performance) {
console.info("window.performance works fine on this browser");
}
if (performance.navigation.type == 1) {
console.info( "This page is reloaded" );
location.hash='/app/homepage'
} else {
console.info( "This page is not reloaded");
}
扩展资料
判断一个网页是刷新还是关闭
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body οnunlοad=fclose() οnlοad=fload() οnbefοreunlοad=bfunload()>
<script>
var s = "test";
function fclose()
{
if(s=="no")
alert('unload me!='+s+'这是刷新页面!');
else
alert('这是关闭页面');
}
function fload()
{
alert("load me!="+s);
}
function bfunload()
{
s = "no";
}
</script>
</body>
</html>
2018-06-27 · 百度知道合伙人官方认证企业
判断的原理就是通过离开页面行为时间onunload触发时间去检测此时的浏览器的窗口大小,根据大小由此判断用户是刷新,跳转或是关闭行为程序。
代码如下
window.onunload = function(){
var a_n = window.event.screenX - window.screenLeft;
var a_b = a_n > document.documentElement.scrollWidth-20;
if(a_b && window.event.clientY< 0 || window.event.altKey){
alert('关闭页面行为');
}else{
alert('跳转或者刷新页面行为');
}
}
<body onload="refresh()">
...........................................
<script type="text/javascript">
function refresh()
{
alert("刷新!");
}
</script>
弹出警告框就表示刷新了。
呢个次次都弹出啦,有何意义
呢个次次都弹出警告框啦,有何意义
页面加载弹,刷新又弹,意义何在
<script language="javascript">
var _s="close";
window.onunload = function(){
if(_s=="fresh")
alert('页面刷新了');
}
window.onbeforeunload = function(){
_s="fresh";
}
</script>
如果页面第一次加载要调用B函数,刷新页面就不调用,需要判断下是否已刷新页面,如何操作?
没搞出来,,坐等行货大神~~~