Reputation: 183
Hey I have this little javascript bookmark
javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite#bookmark'); })()
How can I get the url of the current website into that url?
I have heard of using document.URL
But I am not sure how to get that into the URL in the bookmark with the URL of the site currently browsing. Meaning at the moment the result is http://www.mywebsite.com/index.php?currentsite=document.URL#bookmark
Thanks
Upvotes: 0
Views: 215
Reputation: 3073
I'm not exactly sure what you are talking about but if you are trying to get the full URL along with the anker you can document.location.href
http://www.w3schools.com/jsref/prop_doc_url.asp
You can access the parts of the URL using Location Object http://www.w3schools.com/jsref/obj_location.asp
your code should look like this:
function(){
var url = document.location.href;
window.open('http://www.mywebsite.com/index.php?currentsite = ' + url);
}
Not sure if thats what you where trying to do.
Upvotes: 1
Reputation: 2615
Try using this instead:
javascript:( function(){window.open('http://www.mywebsite.com/index.php?'+document.location.href+'#bookmark');} )()
Upvotes: 2
Reputation: 658
Just use window.location.href - like this:
window.open( 'http://<someurl>?' + window.location.href + '#somebookmark' );
window.location.href will give you the href of current frame.
Upvotes: 1
Reputation: 393
try window.location or document.location.href or window.location.href I forgot which one works :)
Upvotes: 2
Reputation: 173522
javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite=' + encodeURIComponent(location.href) + '#bookmark'); })()
Upvotes: 3