{"id":862,"date":"2020-01-21T06:15:00","date_gmt":"2020-01-21T06:15:00","guid":{"rendered":"http:\/\/shaplakanon.com\/wpsupport\/?p=862"},"modified":"2020-02-10T09:24:08","modified_gmt":"2020-02-10T09:24:08","slug":"how-to-get-current-page-url-with-javascript","status":"publish","type":"post","link":"https:\/\/shaplakanon.com\/wpsupport\/how-to-get-current-page-url-with-javascript\/","title":{"rendered":"How to get current page URL with javascript?"},"content":{"rendered":"\n
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.<\/p>\n\n\n\n
var origin = window.location.origin; \n\/\/ Returns base URL (https:\/\/example.com)\n var url = window.location.href; \n\/\/ Returns full URL (https:\/\/example.com\/path\/example.html) \nvar pathname = window.location.pathname; \n\/\/ Returns path only (\/path\/example.html)<\/pre>\n<\/div>\n\n\n\n