JavaScript

How to Get the Current URL with JavaScript

You can use the property window.location.href of JavaScript to get the full URL of the current page, which contains the domain name, query string, identifier, etc. The following example displays the URL of the current page by clicking on the button.
 

How to Get the Current URL with JavaScript
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Get the Current URL</title>
		<script>
			function url() {
				alert("The URL of this page is: " + window.location.href);
			}
		</script>
	</head>
	<body> 
		<button type="button" onclick="url();">Get the Current URL</button>
	</body>
</html>
Result
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *