There are many other options than href in window.location . See the full link here: https://developer.mozilla.org/en/DOM/window.location
What you are looking for as a starter could be window.location.hostname :
"host name (without port number or square Brackets)."
In the example URL http://[www.example.com]:80/search?q=devmo#test the host name will be www.example.com .
If you also want to include the path and force the http: // protocol, try:
'http://' + window.location.hostname + window.location.pathname;
As a side note, a great trick to get the same parameters from a different URL as window.location is to create an empty anchor:
var a = document.createElement('a'); a.href = 'http://www.example.com:80/search?q=devmo#test'; console.log('http://' + a.hostname + a.pathname);
source share