自学做网站界面合肥seo推广公司
BOM:浏览器对象模型,可以让我们通过js来操作浏览器
window 代表整个浏览器窗口 同时也是页面中的全局对象
Location 代表浏览器地址栏信息
Navigator 代表浏览器信息 可以获取不同的浏览器信息
History 代表浏览器的历史记录
Screen 代表用户的屏幕信息
常用的操作:
//警告框window.alert("这是一个消息");//确认框if(window.confirm("确定吗?")){window.alert("确定");}else{alert("取消");}//提示框let res = window.prompt("请输入账号","默认值");console.log(res)//window.setTimeout(function ,毫秒)//延时器var timer = window.setTimeout(function () {console.log("执行了一段业务")},2000);//清除延时器window.clearTimeout(timer);//定时器 间隔 毫秒 执行一次let timer = window.setInterval(function () {console.log("执行了定时器")},1000);//清除定时器window.clearInterval(timer)//打开窗口window.open("./14.数组.html","测试数据".....);//关闭当前窗口let btn = document.getElementById("btn");btn.onclick = function () {window.close();}//移动窗口window.moveTo(x,y);//获取浏览器信息console.log(navigator.userAgent);function openWin() {myWindow = window.open('', '测试弹窗', 'width=200,height=200')myWindow.document.write("<h1>这是一个弹窗</h1>")}function moveWin() {myWindow.moveTo(300, 300);myWindow.focus();}function resizeWin() {myWindow.resizeTo(300, 300);myWindow.focus();}//Location 获取地址栏信息console.log(location) //返回locationconsole.log(location.href) //返回完整的URLconsole.log(location.origin) //返回当前页面的域名console.log(location.protocol) //返回一个URL协议console.log(location.hostname) //返回URL的主机名console.log(location.host) //返回一个URL的主机名和端口console.log(location.port) //返回一个URL服务器使用的端口号console.log(location.pathname) //返回的URL路径名console.log(location.search) //返回一个URL的查询部分// history 浏览器历史记录console.log(history)