19-Jun-2023
.
Admin
Today, I will let you know example of get current page url. let’s discuss about path. I would like to share with you host and hash using jquery. This post will give you simple example of getting url hash location. you will do the following things for and using it in jquery.
To get the current page URL, path, host and hash using jQuery, you can use the following code:
Example 1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How To Get Current Page URL, Path, Host and hash using jQuery? - NiceSnippets.Com</title>
</head>
<body>
</body>
<script type="text/javascript">
var currentPageUrl = window.location.href;
// Get current page path
var currentPagePath = window.location.pathname;
// Get current page host
var currentPageHost = window.location.host;
// Get current page hash
var currentPageHash = window.location.hash;
</script>
</html>
You can then use these variables to manipulate or display the current page information as needed.
#JavaScript