Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get URL from browser address bar?

Tags:

javascript

url

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

.........................................

I have tried using

document.location 

but that shows what page the user is on (i.e. 404 page address), not what they have typed

like image 929
Constructor Avatar asked Nov 14 '10 17:11

Constructor


People also ask

How do I access the URL in my browser?

Find the URL of the website.The website's URL is in the address bar, which is usually at the top of your web browser window. This bar may be at the bottom of the window in Chrome on some Androids.

How do I show the URL bar in Safari?

1 – Select Safari from the top menu bar. 2 – Click Preferences. 3 – Select the Advanced tab. 4 – Check the box beside Show full website address.


1 Answers

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).

like image 195
jwueller Avatar answered Sep 24 '22 15:09

jwueller