views:

78

answers:

1

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?

+1  A: 

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