jquery - Check link variable with JavaScript -


take example, page follows:

http://www.example.com/page.asp?page=about

with javascript, how can check if window's location contains ?page=about?

this code have far, can't seem work.

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

please :)

thanks

use .indexof() instead of contains

if ( window.location.href.indexof('?page=about') > -1)  

window.location contains location object .. href attribute holds url

check fiddle


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -