javascript当中history的用法

马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。



例 1.6(firstIEFF.html)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>

</HEAD>

<BODY>
<A HREF="second.html">进入second.html</A>
</BODY>
</HTML>




second.html




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<TITLE> New Document </TITLE>

<SCRIPT LANGUAGE="JavaScript">
<!--
/*Window.history (Property)
This property returns a history object for this window.

Property/method value type:    History object
JavaScript syntax:    -    history
-    myWindow.history

.*/
window.onload=function(){
    var num = Math.round(Math.random()*100);

    document.getElementById("num").innerHTML=num;
}
//-->
</SCRIPT>
</HEAD>

<BODY>
qixy: the function of history.go(x) is the same as the button of IE itself, so think about the function of the button of IE itself
<INPUT TYPE="button" value="后退" onclick="history.go(-1)">&nbsp;
<INPUT TYPE="button" value="前进"  onclick="history.go(1)">&nbsp;
<INPUT TYPE="button" value="刷新"  onclick="history.go(0)">
<p>刷新演示:<div id="num"></div></p>
<A HREF="third.html">进入next</A>

<!-- 若使"前进"按钮有效果,一定是已经去过下一个url;"后退"按钮也同理 -->
</BODY>

</HTML>





third.html



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY>
<P>
<INPUT TYPE="button" value="后退" onclick="history.back()"><!-- 与history.go(-1)等同 -->
</BODY>
</HTML>