BOM:浏览器对象模型:
| window(全局作用域)对象 | location对象 | screen 屏幕对象 | history历史模式对象 |
|---|---|---|---|
| alert(); | href | go() | |
| confirm(); | Hash | ||
| prompt(); | URL | ||
| setInterval(); | reload() | ||
| setTimeout(); |
window.alert('myname');var a = confirm('你确定离开网站吗?');console.log(a);var str = prompt('请输入你的内容?','liujing');//liujing是默认值console.log(str);
setInterval();延迟性的操作
setTimeout();周期性循环操作
clearInterval();清除定时器
// setInterval();// setTimeout();//延迟性的操作 等待操作window.setTimeout(function(){console.log('liujing');},2000)//即使延迟时间为0;但是也是队列//周期性循环的语句var num = 0;var timer = null;window.setInterval(function(){num++;if(num > 5){clearInterval(timer);return;//直接跳出循环}console.log('num:'+ num);},1000)// clearInterval()清除定时器
// http://localhost:63342/WWW/BOM/index.html?user=111&pwd=1222console.log(location.host);//localhost:63342console.log(location.hostname);//localhostconsole.log(location.href);//http://localhost:63342/WWW/BOM/index.html?_ijt=3l2tefda44uql91v587ner77jiconsole.log(location.pathname);///WWW/BOM/index.htmlconsole.log(location.port);//63342console.log(location.protocol);//http: https:加密的console.log(location.search);//?user=111&pwd=1222// 位置操作//2秒之后跳转猿圈 https://www.apeland.cn/websetTimeout(function(){// location.href='https://www.apeland.cn/web'; //有历史记录// location.replace('https://www.apeland.cn/web');//没有历史记录location.reload();},2000)
[^注意:一定需要通过站点去访问页面]:
如何检测当前浏览器上的插件(navigator对象):
console.log(navigator);console.log(navigator.plugins);function hasPlugins(name){//如果有插件 返回true 反之亦然name = name.toLowerCase();for(var i=0;i<navigator.plugins.length;i++){if(navigator.plugins[i].name.toLowerCase().indexOf(name)>-1){//有此插件return true;}else{return false;}}}// alert(hasPlugins('Flash'));alert(hasPlugins('Chrome PDF Plugin'));
// 历史记录// console.log(history);var count = 0;var a = setTimeout(function(){count++;console.log(count);history.go(0);//原网页刷新 1:代表前进按钮按一次;-1:代表后退按钮后退1次},2000)console.log(a);
[^注意:go(2)代表网页前进2次;go(-2)代表网页后退2次]:
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号