
This is very basic and hot question asking every time in interview. How to get current page url in js?
Here you will get one JSON object with multiple keys. lets understand few important keys:-
- host: "boyonweb.blogspot.com" - host will return you domain with extension without http/https.
- href: "https://boyonweb.blogspot.com/2020/05/how-to-use-every-function-in-javascript.html" - this
- key will give complete full url of current page.
- origin: "https://boyonweb.blogspot.com"- origin key will give host name with its protocol.
- pathname: "/2020/05/how-to-use-every-function-in-javascript.html" - it will give path with protocol
- and domain name
- protocol: "https:"- it will give you protocal type like https/http/ftp etc.
Example of One website you can see here :
Website name : https://marketingdukaan.com/
Comments
Post a Comment