How
to access current URL in the javascript?
When you
required current path in the javascript then need to use some “window.location”
properties as given example below:
URL
Syntax:
<protocol>//<hostname>:<port>/<pathname><search><hash>
OR
Protocol://
hostname: port/pathname?search#hash
For
Example URL:
window.location.href
- complete URL as (https://www.anythinglearn.com/)
window.location.protocol
- a protocol of the URL as (Http, https)
window.location.hostname
- hostname mean company name of the URL as (www.anythinglearn.com)
window.location.port
- Port of the server uses for the URL as (21, 22)
window.location.pathname
- a pathname of the URL as (/2019/06/how-to-call-image-in-react.html)
window.location.host
- hostname mean name of the URL as (www.anythinglearn.com)
After hostname complete URL be search or query string.
window.location.search
- Query portion of the URL as (?q=react)
window.location.hash
- the anchor portion of the URL as (#abc?nyc#xyz.xyzs)
window.location.origin
– origin work as href, complete URL as (https://www.anythinglearn.com/)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.