BOM常用方法

1、href、assign、replace跳转

document.onclick=function(){

console.log(location.href);

location.href="http://www.163.com";

location.assign("http://www.163.com");

ocation.replace("http://www.163.com");

}

image-20200405230629938

//三者跳转的特点是

//href跳转页面留有历史记录,还可以获取当前页面的网址

// assign跳转页面留有历史记录

//replace替换当前页面,这个没有历史记录

 

2、hash、search

console.log(location.hash);//获取地址栏中#后面的内容,也就是锚点标记名

console.log(location.search);//获取地址栏中?后面的内容,?号后面一般是访问地址的参数

 

3、history 历史记录

history.back();//回退

history.forward();//前进

history.go(1);//跳转到第几个负数是回退,正式是前进,0是刷新页面

 

 

 

4、screen 屏幕

console.log(screen.width,screen.height); //全屏幕宽高

console.log(screen.availWidth,screen.availHeight);//不带任务栏的屏幕宽高

image-20200405230302152

 

5、用户浏览器信息

console.log(navigator.userAgent);

image-20200405230428658

 

 

6、使用window的方法时可以不用加window

window.open();

open()

alert();

window.alert();

 

7、弹窗限制

open("http://163.com","我的网页","width=200,height=200");

// 现在基本不用了 浏览器已经做了对弹出框的限制

image-20200405230120022

 

8、关闭窗口

document.onclick=function(){

close();

}

 

9、视窗宽高和浏览器宽高

console.log(innerWidth,innerHeight);//视窗宽高

console.log(outerWidth,outerHeight);//浏览器窗口宽高

 

10、重载 以前用,现在不用

location.reload();

 

 

猜你喜欢

转载自www.cnblogs.com/wufeiqiang/p/12639854.html
bom
今日推荐