Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

JS - get current URL

0 votes
3 views
added Jun 12 in Javascript by birdygeek Sergeant (2,060 points)
<!--Click 'button' to get the current URL-->
<button onclick="myFunction()">button</button>

<p id="result"></p>

<script>
function myFunction() {
    var x = location.href;
    document.getElementById("result").innerHTML = x;
}
</script>

1 Response

0 votes
responded Jun 12 by Callum Sergeant (1,430 points)
<script>
document.getElementById("demo").innerHTML = 
"The full URL of this page is:<br>" + window.location.href;
</script>
lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...