how to get current url in javascript?

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

For Example URL:

window.location.href - complete URL as (
window.location.protocol -   a protocol of the URL as (Http, https)
window.location.hostname - hostname mean company name of the URL as (
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) - hostname mean name of the URL as (

After hostname complete URL be search or query string. - 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 (

No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.