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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -