BOM_window属性和Location
BOM_window属性
属性:
1、获取其他BOM对象:
history:对 History 对象的只读引用。
location:用于窗口或框架的 Location 对象
Navigator:对 Navigator 对象的只读引用
Screen:对 Screen 对象的只读引用
2、获取DOM对象
document:对 Document 对象的只读引用
//获取history var h1 = window.history; var h2 = history; alert(h1) alert(h2) var openid = window.document.getElementById("openBtn"); alert(openid);
BOM_Location
Location:地址栏对象
1、创建(获取)
1、window.location
2、location
2、方法
reload():重新加载当前文档
3、属性
href:设置或返回完整的URL
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input type="button" id="btn" value="刷新"> <input type="button" id="go" value="bd"> <script> //reload方法:定义一个按钮,点击按钮,刷新当前页面 //获取按钮 var btn = document.getElementById("btn"); //绑定单击事件 btn.onclick = function () { //刷新页面 location.reload(); } //获取href var href = location.href; // alert(href); //点击按钮,访问页面 var go = document.getElementById("go"); go.onclick = function () { location.href = "http://www.baidu.com"; } </script> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix