location.href和window.open的区别

location.href的用法

在前面页面打开URL location.href

在父页面打开URL parent.location.href

在顶层页面打开URL top.location.href

window.open的用法

window.open()方法用于打开一个新的浏览器窗口,该方法的语法结构如下:

window.open(strUrl, strWindowName, [strWindowFeatures])

strUrl:要在新打开的窗口中加载的URL。

strWindowName:新窗口的名称。

可选的参数如下

_blank :打开一个新的标签页。这个是默认值

_parent :父页面打开

_self :当期页面打开

_top :顶层页面打开

name:窗口

总结:location.href属性与window.open()方法的区别

Location.href属性与window.open()方法的区别如下所示:

Location.href属性是对当前浏览器窗口的URL地址对象的参考;window.open()方法打开一个新的窗口。

Location.href属性一般用于页面的迭代,也就是重新定位当前页

window.open()方法可以通过新开窗口或者说新开标签页打开一个网址,而location.href属性只能在当前页打开一个网址。