How to Get Current Page URL Information Using JavaScript
javascript urlwindow.locationget current page urljavascript domainurl parameters
Published·Modified·
- Set or get the file name or path of the specified object.
alert(window.location.pathname);
- Set or get the entire URL as a string.
alert(window.location.href);
- Set or get the port number associated with the URL.
alert(window.location.port);
- Set or get the protocol part of the URL.
alert(window.location.protocol);
- Set or get the fragment following the hash symbol ("#") in the href attribute.
alert(window.location.hash);
- Set or get the hostname and port number of the location or URL.
alert(window.location.host);
- Set or get the part following the question mark in the href attribute.
alert(window.location.search);
- Get the value of a variable (extract the part after the equals sign).
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=') + 1, url.length);
- Get the domain name of the current webpage.
var domain = document.domain;
Original source: How to Get Current Page URL Information Using JavaScript (JS Get Current Website Information). All rights reserved by the original author. If there is any infringement, please contact QQ: 337003006 for deletion.