How to get current page URL with javascript?

If you are writing some javascript and need to get current current page url, the following code is useful. This is just give an idea to new javascript learners. If you need help, comments below.

 var origin   = window.location.origin;   
// Returns base URL (
 var url      = window.location.href;     
// Returns full URL ( 
var pathname = window.location.pathname; 
// Returns path only (/path/example.html)


Leave a Reply

Your email address will not be published. Required fields are marked *