Monday, 5 May 2014

JQuery "contains"-method incompatible in google chrome

Scenario:

I found this problem when I was testing my MVC application in google chrome. It was working fine on Mozilla but chrome show the error that jquery "contains" is not a valid function. :(

Solution:

Ok fine. If  "contains" is not a valid function please use "indexOf" which has cross browser compatibility.

Format:

var path = somePath;

if(path.contains("xyz"))
{
   alert("hello"); // works fine in mozilla
}

now, with indexOf it should be

if(path.indexOf("xyz") > -1)
{
   alert("hello"); // cross browser compatible
}

1 comment:

  1. Yeah! Post a bug to Google. In the mean time, this work around works .. right click the bookmark, and choose open in a new tab! Hack Facebook Account Free

    ReplyDelete