Is there any way to detect what page you are on in JavaScript?
Why I want to know is so that i can detect what page i am on, and then set the style of an element accordingly.
document.URL
will get you the URL of the current page.
To check for a specific page you would use:
if ( document.URL.includes("homepage.aspx") ) {
//Code here
}
Get url of page are you on
location.href
Or
document.URL
Set style to element by id:
document.getElementById('mydiv').style.border = '1px solid black';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With