Wednesday, April 7, 2010

Using indexof in Javascript

Hi all,
You know well about -

indexof() returns the position of first occurrence of a specified value.


window.self.location returns the path of the window.



<script type="text/javascript">
var url = ''+ window.self.location;
if (url.indexOf('yoursite.com')!=-1)
{
document.getElementById('wrapper').style.backgroundColor ='green';
//You can modify here
}
</script>

No comments: