MyBB Community Forums

Full Version: JavaScript current URL?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to make this code work.

<script>
function DoSubmit(){
 url = window.location.href;
  document.popuploginform.url.value = 'url';
  return true;
}
</script>


I want to replace the URL with current page URL?
Take the quotes off the 'url'. You're setting it to the string 'url' instead of the variable url.

<script>
function DoSubmit(){
 url = window.location.href;
  document.popuploginform.url.value = 'url';
  return true;
}
</script>

or even just

<script>
function DoSubmit(){
  document.popuploginform.url.value = window.location.href;
  return true;
}
</script>
+1 works nicely. Thanks so much.

P.S. do you know how can I remove these from the string:

#login
#close
Two ways, firstly you could stop them being added to the URL by changing the onClick of the open/close buttons to "......; return false;"

Or, you could split the URL at # and just use the first part:

window.location.href.split("#")[0]
Thanks you so much.