0

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

McDan Garrett
  • 183
  • 1
  • 3
  • 15

5 Answers5

3
javascript:(function(){ window.open('http://www.mywebsite.com/index.php?currentsite=' + encodeURIComponent(location.href) + '#bookmark'); })()
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
2

try window.location or document.location.href or window.location.href I forgot which one works :)

Sanket
  • 393
  • 1
  • 3
  • 12
2

Try using this instead:

javascript:( function(){window.open('http://www.mywebsite.com/index.php?'+document.location.href+'#bookmark');} )()
boz
  • 4,891
  • 5
  • 41
  • 68
Sunil Dodiya
  • 2,605
  • 2
  • 18
  • 21
1

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.

Mr MT
  • 658
  • 8
  • 15
1

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.

Levi Putna
  • 2,863
  • 6
  • 30
  • 47