Need current browser location information? Keep in mind that the JavaScript's window.location object gives you all of that information about the window's current location.
需要当前浏览器的位置信息? 请记住,JavaScript的window.location对象为您提供了有关窗口当前位置的所有信息。
Javascript窗口属性用于:
https://davidwalsh.name:80/article.php?s=david+walsh+blog#myAnchor (Javascript Window Properties for:
https://davidwalsh.name:80/article.php?s=david+walsh+blog#myAnchor)
window.location = {
hash: '#myAnchor',
host: 'davidwalsh.name',
hostname: 'davidwalsh.name',
href: 'https://davidwalsh.name:80/article.php?s=david+walsh+blog#myAnchor',
pathname: '/article.php',
port: '80',
protocol: 'http:',
search: '?s=david+walsh+blog',
replace: 'function replace() { [native code] }',
assign: 'function assign() { [native code] }',
reload: 'function reload() { [native code] }'
}
JavaScript重定向 (Javascript Redirect)
How can this be used? One example is doing a JavaScript redirect:
如何使用? 一个示例是执行JavaScript重定向:
window.location = 'https://davidwalsh.name'; //redirects to homepage
Or you could use it to compare link hrefs to find out if a link is external or internal. Or you could build a sweet history manager!
或者,您可以使用它来比较链接href,以找出链接是外部链接还是内部链接 。 或者您可以建立一个甜蜜的历史经理 !