xxxxxxxxxx
var currentURL = $(location).attr('href');
var currentURL = window.location.href;
xxxxxxxxxx
var currentURL = $(location).attr('href'); //jQuery solution
var currentURL = window.location.href; // raw javascript
xxxxxxxxxx
var currentUrl = window.location.href;
// Use console.log to display the retrieved URL
console.log(currentUrl);
xxxxxxxxxx
var currentURL = $(location).attr('href'); //jQuery solution
var currentURL = window.location.href; // raw javascript
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Get Current Page URL</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
var currentURL=location.protocol + '//' + location.host + location.pathname;
alert(currentURL);
});
});
</script>
</head>
<body>
<button type="button">Get URL</button>
</body>
</html>
xxxxxxxxxx
var pathname = window.location.pathname; // Returns path only (/path/example.html)
var url = window.location.href; // Returns full URL (https://example.com/path/example.html)
var origin = window.location.origin; // Returns base URL (https://example.com)