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
Question
Take for example, a page as follows:
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
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