JavaScript打开新窗口的方法

​ 在开发网站的时候,我们经常有这种需求,即点击一个按钮然后跳转到另一个页面,今天博主来介绍JavaScript中利用BOM对象跳转页面的方法。

1.Window.open()

Window.open("http://www.w3school.com.cn");

2.location.herf

location.href = "http://www.w3school.com.cn";

3.location.replace()

location.replace("http://www.w3school.com.cn");

4.location.assign()

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

注意

其中window对象打开一个新窗口
而location对象不打开新窗口,将在原来窗口中打开新的地址(可理解为重定向)

参考文献

["http://www.w3school.com.cn"](http://www.w3school.com.cn)

猜你喜欢

转载自blog.csdn.net/codeliang20/article/details/106433884