js 如何判断页面是否刷新???

JavaScript028

js 如何判断页面是否刷新???,第1张

//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/htmlcharset=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>

<mce:script type="text/JavaScript"><!--function close(evt) //author: sunlei{var isIE=document.all?true:falseevt = evt ? evt :(window.event ? window.event : null)if(isIE){//IE浏览器var n = evt.screenX - window.screenLeftvar b = n >document.documentElement.scrollWidth-20if(b &&evt.clientY<0 || evt.altKey){//alert("是关闭而非刷新")window.location.href="../include/logout.PHP"}else{//alert("是刷新而非关闭")return false}}else{//火狐浏览器if(document.documentElement.scrollWidth!=0){//alert("是刷新而非关闭")//window.location.href="report_list.php?ss=1"return false}else{alert("是关闭而非刷新")//window.location.href="repost_list.php?ss=0"//alert("bbbbbbb")}}}// --></mce:script><BODY onunload="close(event)">

定义一个全局变量,比如

var global = 0

if(global >0)

alert("页面未刷新")

else

global++

当页面加载时,即把全局变量修改值。