English 中文(简体)
Bookmarklet to grab the current website address but without http://
原标题:

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?

问题回答

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.





相关问题
How to get IP address from sockaddr

I want to try and get the ip address of a client after calling accept. This is what I have so far, but I just end up getting some long number that is clearly not an ip address. What could be wrong? ...

printing ip addresses using gdb

I am debugging a networking code and want to print ip addresses which are declared as int32. when i print it using gdb print command, i get some values which is not much meaningful. How can i ...

Using Clients IP as the Servers IP

This might be one of those "huh, why?" questions, but I figured it would be worth the try. How would one, from a server-side application, use the clients IP address as the applications IP address to ...

where is class E ip addresses?

I am reading Richard Stevens TCP/IP illustrated Vol1.He said class E ip addresses are reserved for future use.Considering he wrote the book at 1994,now is the future.So where is the class E ip ...

multicast ip address - blocked in call to recvfrom

i am writing a simple multicast application. i intend to run it on localhost. i have done the following: char *maddr; . . . sendfd = socket(...); struct sockaddr_in sasend; sasend.sin_family = ...

热门标签