一、window:环境信息与弹窗

innerWidth、navigator、alert 全都是 window 的成员,平时省略前缀直接用。

视口 innerWidth × innerHeight点上面按钮读取 语言 / 在线— devicePixelRatio—

二、location 与 history:地址栏

hash 变化不刷新页面、还会进历史记录——老式前端路由(#/page)就靠它。示例跑在沙箱里,history.pushState 会抛 SecurityError,所以只演示 hash。

三、localStorage:会记住的存储

存储探测中…

本示例在沙箱 iframe 中运行,浏览器会禁用 localStorage(写入抛 SecurityError)。代码用 try/catch 探测后自动降级到内存 Map——把同样的代码放到普通页面,数据会真正落盘、刷新后仍在。

[迷你控制台]