jQuery attr() get the current page url

Description

jQuery attr() get the current page url

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Get Current Page URL</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            var pageURL = $(location).attr("href");
            document.getElementById("demo").innerHTML = pageURL;
        });/* w w w  .j ava2s  .c o  m*/
    });
</script>
</head>
<body>
    <p id="demo"></p>
    <button type="button">Get URL</button>
</body>
</html>



PreviousNext

Related