17.获取DOM节点

发布时间 2023-09-26 21:25:48作者: 一名狗书匠&

window 代表浏览器窗口
//alert 弹窗
window.alert('我是你爹')
//获取浏览器窗口大小
window.innerHeight
678
window.innerWidth
668
window.outerHeight
752
window.outerWidth
1280

navigator 封装了浏览器的信息,大多数时候不会用这个对象,容易被人为修改
screen 代表屏幕
获取屏幕的宽度和高度
screen.height
800
screen.width
1280

-----------------------------------------------------------------------------

location:代表当前网站页面的URL信息
location.reload() 刷新页面
location.assign('目标网址') 设置新的地址
document:代表当前的页面文档信息
//修改当前页面的标题
document.title='博客园'

获取具体的文档树节点
document.getElementById('具体ID')
document.getElementsByTagName('具体标签');
document.getElementsByClassName('具体class名字');
父类名字.children 获取所有子类的节点

获取cookie
document.cookie 获得当前页面的cookie

history (不建议使用)
//前进
history.forward()
//后退
history.forward()