JavaScript Uzyskaj bieżący adres URL
var currentUrl = window.location.href;
Grepper
var currentUrl = window.location.href;
window.location.pathname; // Returns path only (/path/example.html)
window.location.href; // Returns full URL (https://example.com/path/example.html)
window.location.origin; // Returns base URL (https://example.com)
function getURL() {
alert("The URL of this page is: " + window.location.href);
}
// this gives you just the URL without params
var currentUrlWithoutParams = window.location.href.split("?")[0];
console.log(window.location.href);
As noted in the comments, the line below works, but it is bugged for Firefox.
document.URL
const isAbsoluteUrl = url => /^[a-z][a-z0-9+.-]*:/.test(url);
// Example
isAbsoluteUrl('https://1loc.dev'); // true
isAbsoluteUrl('https://1loc.dev/foo/bar'); // true
isAbsoluteUrl('1loc.dev'); // false
isAbsoluteUrl('//1loc.dev');