我需要用字符串形式的参数检索整个 URL。例如,我需要检索以下 URL:
http://www.keytometals.com/page.aspx?ID=CheckArticle&site=kts&LN=EN&NM=349
我试过使用:
document.location.href,
document.URL,
window.location.href
但它只检索了 URL 的一部分:
http://www.keytometals.com/page.aspx
如何获取包含当前URL及其参数的字符串?
一个更新:我用过
window.content.document.location.href
我有以下网址:
http://www.keytometals.com/page.aspx?ID=CheckArticle
遗憾的是,它仍然是URL的一部分。有人可以帮助我如何将整个 URL 获取为字符串吗?
谢谢!
最佳答案
您应该对整个 URL(包括查询字符串)使用 window.location.href
。
看看Mozilla's documentation了解更多信息和其他属性。
这是关于如何 Parse query string in JavaScript 的另一篇不错的 StackOverflow 帖子.
关于javascript - 如何使用参数检索整个 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6475237/