JavaScript的window.location

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,以找出链接是外部链接还是内部链接 。 或者您可以建立一个甜蜜的历史经理

翻译自: https://davidwalsh.name/javascript-window-location

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值