Question

Take for example, a page as follows:

http://www.example.com/Page.asp?Page=About

With JavaScript, how can I check if the window's location contains ?Page=About?

This is the code I have so far, but I can't seem to get it to work.

$(document).ready(function(){
if ($(window.location:contains('?Page=About')").length !== 0) 
{
alert("Currently on About page");
}
else {
}
});

Please help :)

Thanks

Was it helpful?

Solution

Use .indexOf() instead of contains

if ( window.location.href.indexOf('?Page=About') > -1) 

window.location contains the Location object .. The href attribute holds the url

Check Fiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top