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

JS - get current URL

0 votes
5 views
added Jun 12 in Javascript by birdygeek Sergeant (2,060 points)
edited Jul 13 by LC Marshal
<!--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,480 points)
edited Jul 13 by LC Marshal
<script>
document.getElementById("demo").innerHTML = 
"The full URL of this page is:<br>" + window.location.href;
</script>
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...