Maison  >  Article  >  interface Web  >  javascript history对象(历史记录)使用方法(实现浏览器前进后退)_基础知识

javascript history对象(历史记录)使用方法(实现浏览器前进后退)_基础知识

WBOY
WBOYoriginal
2016-05-16 17:05:042084parcourir

window.history对象在编写时可不使用 window 这个前缀。为了保护用户隐私,对 JavaScript 访问该对象的方法做出了限制。

方法:

history.back() - 加载历史列表中的前一个URL,这与在浏览器中点击前进按钮是相同的
history.forward() - 加载历史列表中的下一个URL,这与在浏览器中点击前进按钮是相同的

实例:

复制代码 代码如下:






其他方法:

复制代码 代码如下:

history.go(0);//刷新当前页面
//以下是要在浏览器中有历史记录的,否则不会有效果.
history.go(1);//前进一页
history.go(-1);//后退一页
history.go(-2);//后退两页
history.length;//当前窗口包含的历史记录条数
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn