Get URL of where I'm located with JavaScript

Question:

How do I get the current URL on the website? using javascript .

What I want is to know if I can obtain the url of a website, but for example if I am in the /conocenos section /conocenos want to obtain http://sitioWeb/conocenos .

Answer:

in javascript you can get the url with: location.href

<script type="text/javascript">
alert(location.href);
</script>

from window.location

   <script type="text/javascript">
   alert(window.location);
    </script>

In summary you can use:

window.location.href : get the href (url) of the current page.

Scroll to Top