HTML DOM लोकेशन href प्रॉपर्टी URL पथ के अनुरूप स्ट्रिंग लौटाती/सेट करती है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
- href . का रिटर्निंग मान संपत्ति
location.href
- href . का मान संपत्ति सेट
location.href = href
उदाहरण
आइए स्थान href . के लिए एक उदाहरण देखें संपत्ति -
<!DOCTYPE html>
<html>
<head>
<title>Location href</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>Location-href</legend>
<label for="urlSelect">Current URL:</label>
<input type="url" size="30" id="urlSelect" value="https://www.example.com/aboutUs">
<input type="button" onclick="gethref()" value="Get href">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var urlSelect = document.getElementById("urlSelect");
function gethref(){
divDisplay.textContent = 'URL Path: '+location.href;
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -
‘Href प्राप्त करें’ . क्लिक करने से पहले बटन -

‘Href प्राप्त करें’ . क्लिक करने के बाद बटन -
