Vinson

Vinson

BOM

发表于 2023-08-06
Vinson
阅读量 25

JavaScript BOM常用方法

系统对话框

alert("hello");
confirm("确定?");// 返回 true false
prompt("输入文本","默认文本");// 返回输入的值,取消返回 null
window.print();// 打印对话框
window.find();// 查找对话框
js

console.time()

console.time("test1")
var div = document.getElementById("div");
console.timeEnd("test1") 
js

测试从上一个test1到这行代码运行所用的时间

open 及 close

open(url,'新窗口命名','新窗口尺寸''是否替换当前历史记录 boolean 值')
close() // 关闭当前页面
js

JavaScript location URL 地址对象

完整的 URL 地址:

协议:// 主机名:端口号 /路径/ ?查询字符串 #锚点

如:https://127.0.0.1:5500/javascript.html/?a=ssa&bd=asd#aaa

location.hash // #aaa      哈希值
location.host // 127.0.0.1:5500 域名+端口
location.hostname // 127.0.0.1  域名
location.href // https:127.0.0.1:5500/?a=ssa&bd=asd#aaa url 地址 toString() 也能返回这个值
location.origin // https:127.0.0.1:5500 文件来源地址
location.pathname // /JavaScript.html 文件路径
location.port // 5500 端口
location.protocol // https: 协议
location.search // ?a=ssa&bd=asd 表单提交的数据
location.port = 8080; // 可以用这样的方法修改上面的值,除了 hash 值外,页面都会以新的 URL 重新加载

location = 'http:// www.163.com';
location.assign(url)// 在当前窗口跳转到这个URL
location.replace("http:// baidu.com"); *// 在当前窗口替换成新的 URL 用户将不能回到前一个页面*
location.reload();// 重新加载(可能从缓存中加载)
location.reload(true);// 重新加载(从服务器重新加载)
js

JavaScript history 历史记录

history.go(-1);// 后退一页
history.go(0);// 刷新当前页面
history.go(2);// 前进两页
history.go("wrox.com");// 跳转到最近 wrox.com 的页面
history.back();// 后退一页
history.forward();// 前进一页
(history.length == 0) // 这是用户打开宽口后的第一个页面
js

JavaScript navigator 浏览器信息

navigator.appCodeName //浏览器代号
navigator.appName // 浏览名称
navigator.appVersion // 浏览器版本
navigator.cookieEnabled // 是否启用 cookie
navigator.language // 系统语言:标准
navigator.systemLanguage // 系统语言:ie
navigator.platform // 操作系统
navigator.userAgent // 用户代理
js

JavaScript client、client、scroll 窗口位置

p.clientWidth; // 可视宽度 width + padding
p.clientTop; // 上边框宽度
p.clientLeft; // 左边框宽度
p.offsetParent; // 获取上一个带有定位的父元素 
p.offsetWidth; // 占位宽度 width + padding + border
p.offsetLeft; // 距上一个具有定位元素边框的距离

document.documentElement.clientWidth || document.body.clientWidth; // 宽口宽度
document.documentElement.scrollTop/Left;// 已滚动出的距离
js
评论
来发一针见血的评论吧!
表情

快来发表评论吧~

推荐文章
  • 测试文章

    20点赞10评论

  • webpack5(一)

    20点赞10评论