更新时间:2022-06-11 23:28:07
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
.