I have a simple JQuery code that will check the current URL and search for a text; if it exists, execute some code. I am using switch Case. The code works in FF, IE but not in Webkit browsers, Chrome and Safari. Here is the code:
NB: Please assume the current URL include #f3 at the end – so case
$(document).ready(function() {
var checkUrl = $(location).attr('href');
switch (true) {
case (checkUrl.search("#f1") > 0):
//just focus on #f3 below
break;
case (checkUrl.search("#f2") > 0):
//just focus on #f3 below
break;
case (checkUrl.search("#f3") > 0):
//$(".jcarousel-next").trigger("click");
$(".jcarousel-next").triggerHandler('click');
break;
default:
false;
}
});
What this should do is simulate a div with class ".jcarousel-next" being clicked on the page. Chrome and Safari does nothing (apart from just loading the page). Works in Firefox, IE etc…
Any solution guys?
I updated the code and now works for all required browsers (ie7, ie8, ie9, FF, Chrome & Safari). This is an example of what will sit in one of the cases (case2):
for (var i =1; i <2; i++) {
setTimeout(function () { $(“.jcarousel-next”).click(); }, 700 * i);
}
The for loop will action the required code for a certain number of times with a sort of interval to to delay the clicking, otherwise, the loop happens so quick you don’t see it.
Thanks to all for their suggestions.
Abu K.