HTML DOM Location href प्रॉपर्टी URL पाथ से संबंधित स्ट्रिंग को लौटाती या सेट करती है।
सिंटैक्स
निम्नलिखित सिंटैक्स है -
- href प्रॉपर्टी का मान प्राप्त करना
location.href
- href प्रॉपर्टी का मान सेट करना
location.href = href
उदाहरण
आइए Location 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">वर्तमान 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>
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
'Get href' बटन पर क्लिक करने से पहले -

'Get href' बटन पर क्लिक करने के बाद -
