window.location.href property to get the current URI of a web page. Here's how you can do it:
var currentURI = window.location.href; console.log(currentURI);
The above code will log the current URI of the web page to the console. You can use this URI for various purposes, such as sending it as a parameter in an AJAX request or displaying it to the user.
Other Ways to Get the URI
- window.location.pathname: This property returns the path of the current URL.
- window.location.protocol: This property returns the protocol of the current URL (HTTP or HTTPS).
- window.location.host: This property returns the hostname and port number of the current URL.
Here's an example code snippet that demonstrates the use of these properties:
var currentPath = window.location.pathname; var currentProtocol = window.location.protocol; var currentHost = window.location.host; console.log('Path: ' + currentPath); console.log('Protocol: ' + currentProtocol); console.log('Host: ' + currentHost);
The above code will log the path, protocol, and host of the current URL to the console. You can use these properties to extract specific parts of the URL for your application's needs.