How To Get Current Page URL, Path, Host and hash using jQuery?
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.
- How to Show Loading Spinner in JQuery?
- How to Create Ajax Submit Form Using jQuery?
- How To Get, Set and Delete Div Background Image jQuery?
- JQuery Remove All Unwanted Whitespace From String Example
- Body Background Video Using Vide Jquery Example
- JQuery UI Autocomplete Example
- JQuery Split String By Comma Into Array Example
- Form Validation using Jquery Ajax and PHP 8 MySQL