javascript 打开页面window.location和window.open的区别

转自: http://www.jb51.net/article/22616.htm

有时候需要用js来实现页面的打开,因为js下有window.location和window.open的不同实现方法,下面来简单的说明下区别。

window.location = "http://www.xxxxxxxx.net"   跳转后有后退功能
其实应该是  window.location.href

window.location.replace("http://www.xxxxxxxx.net") 跳转后没有后退功能

window.open("http://www.xxxxxxxx.net")   要新的窗口打开链接

这个一般用于简单的弹出页面,现在基本上都被屏蔽掉了 


另一篇:http://guangcai.iteye.com/blog/518345

1.window.location是window对象的属性,而window.open是window对象的方法 
  window.location是你对当前浏览器窗口的URL地址对象的参考!   
  window.open是用来打开一个新窗口的函数! 

【总结】
1、window.open("**")是用新窗口打开URL页面

2、location.href="**"是用当前页面显示URL

【注意 】参考:http://segmentfault.com/q/1010000002729501
bf 6k 5月6日 回答 · 5月6日 更新

The Window.location read-only property returns a Location object with
information about the current location of the document.

Though Window.location is a read-only Location object, you can also
assign a DOMString to it. This means that you can work with location
as if it were a string in most cases
location = 'http://www.example.com' is a synonym oflocation.href = 'http://www.example.com'.

https://developer.mozilla.org/en-US/docs/Web/API/Window/location
location 是 location.href 的簡寫,無論是訪問  還是賦值。
從功能上,location 等於 location.href
但從本體論上,location 是一個對象,location.href 是它的一個屬性。
這種怪異的行爲應該是爲了兼容無疑


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值