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.
var currentUrl = document.URL; var str = currentUrl.indexOf('.php'); if(str >= 0) { alert('php extension is exist'); } else { alert('php extension doesn't exist'); }
Usages
- 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