The HTML DOM URL property returns a string corresponding to the url of the document.
Following is the syntax −
Returning string value
document.URL
Let us see an example of HTML DOM URL property −
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM URL</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-URL</legend>
<h2 >This is a Demo Example</h2>
<input type="button" value="Get Link" onclick="getLink()">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
function getLink() {
divDisplay.textContent = document.URL;
}
</script>
</body>
</html>Output
Before clicking ‘Get Link’ button −

After clicking ‘Get Link’ button −
