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

'गेट पोर्ट' . क्लिक करने के बाद बटन -
