Detect what page you are on JavaScript?

html, javascript

Solution

`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
}

Problem

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.

Original source

Related problems