请求JavaScript地址 [英] Request address in JavaScript
问题描述
可能重复:
使用JavaScript获取当前网址?
如何在JavaScript中获取您所在页面的地址? ?
How do you get the address of the page you are on in JavaScript?
例如,如果我在 somesite.com/javascript/home.html
上有一个脚本,我想要找出请求地址( somesite.com/javascript/home.html
),如何在JavaScript中获取此信息?
For example, if I had a script at somesite.com/javascript/home.html
and I want to find out the request address (somesite.com/javascript/home.html
), how do I get this information in JavaScript?
推荐答案
您需要使用:
document.location
或 window.location
You can read more here. Or there is a little more explanation over there.
澄清事项:
最初由Mozilla开发者中心发布
document.location原来是一个
的只读属性,虽然Gecko
浏览器允许你将它分配给
well 。对于跨浏览器安全,请使用
window.location。
document.location was originally a read-only property, although Gecko browsers allow you to assign to it as well. For cross-browser safety, use window.location instead.
这篇关于请求JavaScript地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!