
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Location href Property
The HTML DOM Location href property returns/sets the string corresponding to the URL path.
Syntax
Following is the syntax −
- Returning value of the href property
location.href
- Value of the href property set
location.href = href
Example
Let us see an example for Location href property −
<!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>
Output
This will produce the following output −
Before clicking ‘Get href’ button −
After clicking ‘Get href’ button −
- Related Articles
- HTML DOM Anchor href Property
- HTML DOM Link href Property
- HTML DOM Base href Property
- HTML DOM KeyboardEvent location Property
- HTML DOM Location hash Property
- HTML DOM Location host Property
- HTML DOM Location hostname Property
- HTML DOM Location origin Property
- HTML DOM Location pathname Property
- HTML DOM Location port Property
- HTML DOM Location protocol Property
- HTML DOM Location search Property
- HTML DOM Location reload() method
- HTML DOM Location replace() method
- HTML DOM tagName Property

Advertisements