We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
var 赋值会自动绑定在 window 对象。
var
window
const 和 let 不会
const
let
如果窗口在 <iframe> <object> <frame> 中,则会产生层级关系(TODO:<object> 和 <frame> 需要研究一下)
<iframe>
<object>
<frame>
top 对象。指向最外层 window
top
parent 对象。指向最临近父 window
parent
最外层的 top 和 parent 相等,都指向 window
self 永远指向 window,这个 API 存在就是为了和 top parent 保持一致性
self
window.screenLeft
window.screenTop
window.moveTo(), window.moveBy() 移动窗口,有些浏览器会禁用
window.moveTo()
window.moveBy()
window.devicePixelRatio
和显示器分辨率有关,代表 1px 在显示器上实际大小为多小像素
1px
innerWidth, innerHeight, outerWidth, and outerHeight
innerWidth
innerHeight
outerWidth
outerHeight
document.documentElement.clientWidth, document.documentElement.clientHeight
document.documentElement.clientWidth
document.documentElement.clientHeight
document.compatMode
BackCompat, 文档使用 quirks mode (怪异模式?)渲染。一些上古的不标准的浏览器
BackCompat
CSS1Compat,文档使用标准模式渲染
CSS1Compat
使用 <!DOCTYPE html> 让浏览器使用标准模式
<!DOCTYPE html>
XHTML 默认都是用标准模式,无需声明
参考:怪异模式的 Bug:https://developer.mozilla.org/en-US/docs/Mozilla/Mozilla_quirks_mode_behavior
对比
document.documentElement.clientHeight/clientWidth
document.body.clientHeight/clientWidth
调整窗口大小 window.resizeTo() 一般会被浏览器禁用
window.resizeTo()
Viewport 指的是浏览器文档内容可见的区域
便宜位置:以下属性作用用一样
window.pageXOffset / window.pageYOffset
window.scrollX / window.scrollY
滚动窗口
window.scroll() window.scrollBy() 一样,滚动相对距离
window.scroll()
window.scrollBy()
window.scrollTo(),传入绝对距离
window.scrollTo()
可以传入一个对象
// normal scroll window.scrollTo({ left: 100, top: 100, behavior: 'auto' }); // smooth scroll window.scrollTo({ left: 100, top: 100, behavior: 'smooth' });
window.open()
alert()
window.location
document.location
URLSearchParams
location.assign() 同 window.location = 和 location.href =
location.assign()
window.location =
location.href =
可以设置其他的 location.hash =, location.search = 等等
location.hash =
location.search =
上述方法都会增加 history 记录
location.replace()
location.reload() 参数传入 true 强制刷新
location.reload()
true
navigator.registerProtocolHandler()
略
改变页面状态而不刷新页面
hashchange 事件
hashchange
HTML5 的 history 对象
history
pushState()
replaceState()
popstate 事件
popstate
按下返回按钮时会触发
event.state 为 pushState() 传入的 state 对象
event.state
history.state 获取当前 state
history.state
state 对象只能传入可以被序列化的对象。DOM 这类不可序列化的对象不可传入
The text was updated successfully, but these errors were encountered:
windowow.scroll 的兼容性更好,但是 iOS 只支持传入 x, y 的形式,不支持 options 对象。如果要实现平滑滚动,可以添加 CSS 属性 scroll-behavior: smooth;
windowow.scroll
x, y
scroll-behavior: smooth;
Sorry, something went wrong.
No branches or pull requests
12 BOM
Window 对象
全局作用域
var
赋值会自动绑定在window
对象。const
和let
不会层级关系
如果窗口在
<iframe>
<object>
<frame>
中,则会产生层级关系(TODO:<object>
和<frame>
需要研究一下)top
对象。指向最外层window
parent
对象。指向最临近父 window最外层的
top
和parent
相等,都指向window
self
永远指向window
,这个 API 存在就是为了和top
parent
保持一致性window 位置和 Pixel Ratio
位置
window.screenLeft
window.screenTop
window.moveTo()
,window.moveBy()
移动窗口,有些浏览器会禁用Pixel Ratio
window.devicePixelRatio
和显示器分辨率有关,代表
1px
在显示器上实际大小为多小像素window 大小
innerWidth
,innerHeight
,outerWidth
, andouterHeight
document.documentElement.clientWidth
,document.documentElement.clientHeight
扩展:
document.compatMode
BackCompat
, 文档使用 quirks mode (怪异模式?)渲染。一些上古的不标准的浏览器CSS1Compat
,文档使用标准模式渲染使用
<!DOCTYPE html>
让浏览器使用标准模式XHTML 默认都是用标准模式,无需声明
参考:怪异模式的 Bug:https://developer.mozilla.org/en-US/docs/Mozilla/Mozilla_quirks_mode_behavior
对比
document.documentElement.clientHeight/clientWidth
document.body.clientHeight/clientWidth
调整窗口大小
window.resizeTo()
一般会被浏览器禁用Viewport 视窗位置
Viewport 指的是浏览器文档内容可见的区域
便宜位置:以下属性作用用一样
window.pageXOffset / window.pageYOffset
window.scrollX / window.scrollY
滚动窗口
window.scroll()
window.scrollBy()
一样,滚动相对距离window.scrollTo()
,传入绝对距离可以传入一个对象
浏览器导航、打开新窗口
window.open()
文档具体 https://developer.mozilla.org/en-US/docs/Web/API/Window/open弹窗被拦截
window.open()
返回值为空或抛出异常系统弹窗
alert()
这些,是同步执行的,会阻塞线程Location 对象
window.location
和document.location
指向一个对象Query 参数
URLSearchParams
工具操作 Location
location.assign()
同window.location =
和location.href =
可以设置其他的
location.hash =
,location.search =
等等上述方法都会增加 history 记录
location.replace()
location.reload()
参数传入true
强制刷新Navigator 对象
navigator.registerProtocolHandler()
Screen 对象
略
History 对象(重要)
改变页面状态而不刷新页面
hashchange
事件HTML5 的
history
对象pushState()
replaceState()
popstate
事件按下返回按钮时会触发
event.state
为pushState()
传入的 state 对象history.state
获取当前 statestate 对象只能传入可以被序列化的对象。DOM 这类不可序列化的对象不可传入
The text was updated successfully, but these errors were encountered: