1

浅学javascript

 2 years ago
source link: https://sakurahack-y.github.io/2022/04/07/%E6%B5%85%E5%AD%A6javascript/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

JavaScript的BOM操作



1、获取浏览器窗口尺寸

获取可视窗口宽度: window.innerWidth
获取可视窗口高度: window.innerHeight


2、浏览器的弹出层

提示框: window.alert('提示信息')
询问框: window.confirm('提示信息') 返回 true和false
输入框: window.prompt('提示信息') 点确定,返回输入框中内容,点取消返回null

3、开启和关闭标签页

开启: window.open('地址')
关闭: window.close()


4、浏览器常见事件

资源加载完毕: window.onload = function() {}
可视尺寸改变: window.onresize = function(){}
滚动条位置改变: window.onscroll = function(){}



5、浏览器历史记录操作

回退页面:window.history.back()
前进页面: window.history.forward

6、浏览器卷去尺寸



卷去的高度

document.documentElement.scrollTop #当有<!DOCTYPE html>用这个
document.body.scrollTop #当没有<!DOCTYPE html>用这个




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK