window.location和location.href之间的区别 [英] Difference between window.location and location.href

查看:1943
本文介绍了window.location和location.href之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 window.location location.href 之间的区别感到困惑。两者似乎都以同样的方式行事。

I am confused as to the difference between window.location and location.href. Both appear to be acting in the same way.

有什么区别?

推荐答案

window.location 是一个对象,它包含有关当前文档位置(主机,href,端口,协议等)的所有信息。

window.location is an object that holds all the information about the current document location (host, href, port, protocol etc.).

location.href 是window.location.href的简写(你从全局对象 - 窗口调用位置,所以这是窗口。 location.href),这只是一个包含当前网站完整网址的字符串。

location.href is shorthand for window.location.href (you call location from global object - window, so this is window.location.href), and this is only a string with the full URL of the current website.

当你为他们分配网址时,他们的行为相同 - 他们会重定向到您指定的页面,但是当您打开浏览器控制台(firebug或开发人员工具)并写入 window.location location.href 。

They act the same when you assign a URL to them - they will redirect to the page which you assign, but you can see differences between them when you open the browser console (firebug or developer tools) and write window.location and location.href.

这篇关于window.location和location.href之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆