如何从浏览器地址栏获取URL? [英] How to get URL from browser address bar?
问题描述
我想做一些js分析,所以我需要知道如何将用户在地址栏中输入的任何内容作为js变量,这样我才能知道最常见的拼写错误。这样我就可以将最常见的拼写错误重定向到正确的地址并减少404页面请求。
I wanted to do some js analytics, so I would need to know how to get whatever the user entered in the address bar as a js variable so I can know what are the most common misspellings. That way I can make redirects for the most common misspellings to the correct adresses and reduce 404 page requests.
浏览器中用户输入的示例:
example of user input in browser:
https://stackoverflow.com/questions
.........................................
.........................................
我尝试过使用
document.location
但是显示用户所在的页面(即404页面地址),而不是他们输入的内容
but that shows what page the user is on (i.e. 404 page address), not what they have typed
推荐答案
这为您提供了用户所在的确切网址:
This gives you the exact url the user is on:
document.location.href
在提交请求之前无法确定用户键入的内容(对于安全原因。
There is no way of determining what the user typed before the request is submitted (for security-reasons).
这篇关于如何从浏览器地址栏获取URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!