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

'प्रोटोकॉल प्राप्त करें' बटन पर क्लिक करने के बाद −
