Alex Rivera | Logout

How to get URL from browser address bar?

Asked 2010-11-14T17:04:40.157
42

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

Edit
Report

2 Answers

1

Many content management systems preserve the url when you land on the 404 page, so you should be able to use document.location.href, then just check the analytics on the error page.

answered 2010-11-14T17:42:16.187
1

This is a good way to get the Reload link address, if there is one, which should have the URL that was typed in to the address bar.

var arr = [], l = document.links;
for(var i=0; i<l.length; i++) {
  arr.push(l[i].href);
}

from: https://stackoverflow.com/a/3871370/1188090

answered 2013-05-14T21:08:37.130

Your Answer