0

The other day you were very helpful. Now I have another question. I have a bookmarklet to grab the current URL or I should say host name (without the http:// part - which is ok) like:

javascript:q=(document.location.host); void(open('http://mysite.com/search.php?search='+location.host,'_self','resizable,location,menubar,toolbar,scrollbars,status'));

The problem is that this bookmarklet only grabs the host name like google.com and not the whole address like google.com/sub/page.htm. Is there any way I can left the http:// part out and grab the remaining url?

Matt
  • 22,721
  • 17
  • 71
  • 112
Bostjan
  • 1
  • 1

1 Answers1

1

If you assume that it's http (not https), then the following should work:

q=document.location.toString().substring(7);

Of course, you need to write q instead of location.host in what follows.

If you want to do it more robustly, use the properties of the Location object and concatenate the ones you want.

Thomas
  • 174,939
  • 50
  • 355
  • 478