Java Script check string in the URL

How to check if some string is exist or not in the url using java script.For a example,I want to check “.php” extension exist in the current url.This can be do like this.


  • This can be use to get current page url(document.URL
  • Can be use to check extension of the current page
  • Can be use to check the position of something in the string or url
  • Can be use to check string/numbers,characters,…etc in the current url

[stextbox id=”black”]
The indexOf() method returns the index at which value can be found in the array.
This method returns -1 means that not exist.[/stextbox]

Published by

Sumith Harshan

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.