History对象

作者: Allenem | 来源:发表于2019-08-17 15:05 被阅读0次

History对象

History 对象包含用户(在浏览器窗口中)访问过的 URL。

History 对象是 window 对象的一部分,可通过 window.history 属性对其进行访问。

Note 注意: 没有应用于History对象的公开标准,不过所有浏览器都支持该对象。

CONTENT

History 对象属性

属性 说明
length 返回历史列表中的网址数

History 对象方法

方法 说明
back() 加载 history 列表中的前一个 URL
forward() 加载 history 列表中的下一个 URL
go() 加载 history 列表中的某个具体页面

History对象属性&对象方法

console.log("历史列表中URL的数量: " + history.length);
// 历史列表中URL的数量: 1
document.write(`<input type="button" value="后退" onclick="window.history.back()">`);
// 后退
document.write(`<input type="button" value="前进" onclick="window.history.forward()">`);
// 前进
document.write(`<input type="button" value="前进2" onclick="window.history.go(2)">`);
// 前进2
document.write(`<input type="button" value="后退2" onclick="window.history.go(-2)">`);
// 后退2

定义和用法

length 属性声明了浏览器历史列表中的元素数量。

♥ 注意:Internet Explorer和Opera从0开始,而Firefox、Chrome和Safari从1开始。

back() 方法可加载历史列表中的前一个 URL(如果存在)。

调用该方法的效果等价于点击后退按钮或调用 history.go(-1)。

forward() 方法可加载历史列表中的下一个 URL。

调用该方法的效果等价于点击前进按钮或调用 history.go(1)。

go() 方法可加载历史列表中的某个具体的页面。

该参数可以是数字,使用的是要访问的 URL 在 History 的 URL 列表中的相对位置。(-1上一个页面,1前进一个页面)。或一个字符串,字符串必须是局部或完整的URL,该函数会去匹配字符串的第一个URL。

语法

history.length

history.back()

history.forward()

history.go(number|URL)

相关文章

  • JavaScriptBOM__History_location(

    目录: 1.History对象 2.location对象 一、History对象 1.什么是History His...

  • history

    History 对象 History 对象包含用户(在浏览器窗口中)访问过的 URL。History 对象是 wi...

  • History in Js

    History 对象 History 对象包含用户(在浏览器窗口中)访问过的 URL。History 对象是 wi...

  • BOM对象(三)———History 对象

    History 对象:History 对象包含用户(在浏览器窗口中)访问过的 URL。History 对象是 wi...

  • History对象

    History对象 History 对象包含用户(在浏览器窗口中)访问过的 URL。 History 对象是 wi...

  • JavaScript基础知识点--BOM之history对象及方

    history 对象 history 对象保存了用户在浏览器中访问页面的历史记录 history 对象方法 bac...

  • history

    window.history属性指向 History 对象,它表示当前窗口的浏览历史。 History 对象保存了...

  • JS History对象

    概述 window.history属性指向History对象,它表示当前窗口的浏览历史。 History对象保存了...

  • BOM(Browser Object Model)

    window.history 返回history对象的引用 window.history.forword() / ...

  • 浏览器内置对象 - history

    Window.history是一个只读属性,用来获取History 对象的引用,History 对象提供了操作浏览...

网友评论

    本文标题:History对象

    本文链接:https://www.haomeiwen.com/subject/hdfksctx.html