javascript get current url

Today, We want to share with you javascript get current url.In this post we will show you javascript get domain from url, hear for java script get current url without query string we will give you demo and example for implement.In this post, we will learn about Simple Java Script Get Current Url with an example.

javascript get current url without parameters

Use the window.location.href Property

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get Current URL in Java Script - www.pakainfo.com</title>
</head>
<body>
    <script>
    function getURL() {
        alert("The URL of this page is: " + window.location.href);
    }
    </script>
     
    <button type="button" onclick="getURL();">Get Page URL</button>
</body>
</html>

How to get the current URL using JavaScript ?

<!DOCTYPE html> 
<html> 

<head> 
	<style> 
		h1 { 
			color: green; 
		} 

		h2 { 
			font-family: Impact; 
		} 

		body { 
			text-align: center; 
		} 
	</style> 
</head> 

<body> 
	<h3>Pakainfo.com</h3> 

	<h2> 
		JavaScript: Simple Example to 
		get the Online website URL ? 
	</h2> 

	<p><b> 
		Trigger on Below Button 
		To Get Current URL 
	</b></p> 
	
	<button onclick="GetURL()"> 
		Get URL 
	</button> 
	
	<p id="url"></p> 
	
	<script> 
		function GetURL() { 
			var paka = document.URL; 
			document.getElementById( 
				"url").innerHTML = paka; 
		} 
	</script> 
</body> 

</html> 

Example : 1 JavaScript Window Location

document.getElementById("example_webpage").innerHTML =
"Your System Page location is " + window.location.href;

Example : 2 Window Location Hostname

document.getElementById("example_webpage").innerHTML =
"Your System Page hostname is " + window.location.hostname;

Example : 3 Window Location Pathname

document.getElementById("example_webpage").innerHTML =
"Your System Page path is " + window.location.pathname;

Example : 4 Window Location Protocol

document.getElementById("example_webpage").innerHTML =
"Your System Page protocol is " + window.location.protocol;

Example : 5 Window Location Port

document.getElementById("example_webpage").innerHTML =
"Your System Port number is " + window.location.port;

I hope you get an idea about java script get url path.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.