Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current url but without the http:// part bookmarklet!

Guys I have a question, hoping you can help me out with this one. I have a bookmarklet;

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

which takes URL of the current webpage and search for it in another website. When I use this bookmarklet it takes the whole URL including http:// and searches for it. But now I would like to change this bookmarklet so it will take only the www.example.com or just example.com (without http://) and search for this url. Is it possible to do this and can you please help me with this one?

Thank you!

like image 823
Bostjan Avatar asked Nov 08 '09 13:11

Bostjan


3 Answers

JavaScript can access the current URL in parts. For this URL:

http://css-tricks.com/example/index.html

window.location.protocol = "http"

window.location.host = "css-tricks.com"

window.location.pathname = "/example/index.html"

please check: http://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/

like image 128
AHMED RABEE Avatar answered Oct 16 '22 17:10

AHMED RABEE


This should do it

location.href.replace(/https?:\/\//i, "")
like image 35
jitter Avatar answered Oct 16 '22 16:10

jitter


Use document.location.host instead of document.location.href. That contains only the host name and not the full URL.

like image 20
Gumbo Avatar answered Oct 16 '22 18:10

Gumbo