Reputation: 153
Here i am trying this code,my url is like this "http://127.0.0.1/magento21/checkout/cart/add/uenc/aHR0cDovLzEyNy4wLjAuMS9tYWdlbnRvMjEvcHJvZHVjdDIuaHRtbA,,/product/2222/".
var url = settings.url;
if ("url:contains('checkout/cart/add')") {
alert('sasas');
}
but this is not working
Upvotes: 0
Views: 189
Reputation: 281774
USe this code to find whether url contains a given string:
var url = 'http://127.0.0.1/magento21/checkout/cart/add/uenc/aHR0cDovLzEyNy4wLjAuMS9tYWdlbnRvMjEvcHJvZHVjdDIuaHRtbA,,/product/2222/';
if (url.indexOf('checkout/cart/add') > -1)
{
alert("your url contains the name string");
}
indexOf find the substring position if it exits in the given string. Running Demo here: jsfiddle
Upvotes: 1
Reputation: 42
U cannot just "url:contains('checkout/cart/add')". In order to check if url contains given pattern. U should write code like:
if (url.indexOf('checkout/cart/add') >= 0)
And it calls string's indexOf to check if it has given substring.
Upvotes: 1