Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
119
rated 0 times [  121] [ 2]  / answers: 1 / hits: 24475  / 11 Years ago, sun, april 21, 2013, 12:00:00

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.


More From » html

 Answers
5

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
}

[#78748] Friday, April 19, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
;