JS - get current URL

0 votes
381 views
added Jun 12, 2018 in Javascript by anonymous
edited Jul 13, 2018 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>

2 Responses

0 votes
responded Jun 12, 2018 by Callum Sergeant (1,440 points)
edited Jul 13, 2018 by LC Marshal
<script>
document.getElementById("demo").innerHTML = 
"The full URL of this page is:<br>" + window.location.href;
</script>
0 votes
responded Jul 3, 2019 by LC Marshal Captain (25,790 points)
window.location.href 

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...