LearnFast.Ninja

JavaScript get current url path

The main idea: Use the document URL property. Test the working example code.

Main idea: Use the document URL property. 
document.URL
 
Working Example Code: 

<!DOCTYPE html>

<html>

<head>

    <title>Untitled Page</title>

    <script type="text/javascript">

        function Show_URL() {

            document.getElementById('MyDiv').innerHTML = document.URL;

        }

    </script>

</head>

<body onload="Show_URL()">

    <div id="MyDiv">

    </div>

</body>

</html>

 
Result:


Tags

javascript

url path