windows.open window.location.href的用法和区别

window.location.href  只能在当前页面打开,不能用新窗口打开

windows.open("URL","窗口名称","窗口外观设定"); 具体使用参数:http://www.w3school.com.cn/jsref/met_win_open.asp

window.open和location.href深入下去,还有以下区别

1.window.location是window对象的属性,而window.open是window对象的方法

  window.location是你对当前浏览器窗口的URL地址对象的参考!  

  window.open是用来打开一个新窗口的函数!

2.window.open不一定是打开一个新窗口!!!!!!!!  

  只要有窗口的名称和window.open中第二个参数中的一样就会将这个窗口替换,用这个特性的话可以在iframe和frame中来代替location.href。

如<iframe name="aa"></iframe>  

  <input type=button   onclick="window.open('1.htm','aa','')">和  

  <input type=button  

   onclick="self.frames['aa'].location.href='1.htm'">的效果一样

3.window.location或window.open如何指定target?

这是一个经常遇到的问题,特别是在用frame框架的时候

解决办法:

window.location 改为 top.location 即可在顶部链接到指定页

window.open("你的网址","_top");

用户不能改变document.location(因为这是当前显示文档的位置)。

window.location本身也是一个对象。

   但是,可以用window.location改变当前文档 (用其它文档取代当前文档),而document.location不是对象。

   服务器重定向后有可能使document.url变动,但window.location.href指的永远是访问该网页时用的URL.

   大多数情况下,document.location和location.href是相同的,但是,当存在服务器重定向时,document.location包含的是已经装载的URL,而location.href包含的则是原始请求的文档的URL.

self.location.href="/url"       当前页面打开新页面,与默认的location.href 或者是windows.location.href 或者是 this.location.href 效果一样

parent.location.href="/url" 在父页面打开新页面

top.location.href="/url"       在顶层页面打开新页面

原文地址:https://www.cnblogs.com/MY0101/p/6374801.html