Jquery.attr('src') Replace Not Working In Ff
Solution 1:
Finally found the solution.
The problem was that src1.lenght
yelded a 'undefined'
value. Although proposed by Alex as the source of the problem, documentation on W3C showed length as a valid property of string.
However, the problem itself was apparently caused by a different handling of the 'undefined'
value in src1.substring(src1.lastIndexOf('media/'), src1.lenght);
. Chrome and IE took the 'undefined'
value simply as not present, therefor the string was parsed till the end. However in FF the substring function failed completely returning the whole string.
After isolating this problem I modified the script using sub-string with one argument only, as I actually wanted it to parse until the end, so the second parameter was not needed at all.
Beneath is the final code that works in Chrome + IE + FF.
$("img[src*='libraries/phpthumb/phpThumbYT.php']").each(function(){
var t=$(this);
var src1= t.attr('src'); // initial srcvar old_src = src1.substring(src1.lastIndexOf('media/')); // extract old source attr var media_id = old_src.substring(6,8); // extract media ID (directory name)
media_id = media_id.replace('/',''); // trim '/' from the end of media_id in case the ID is < 10if ( old_src.indexOf("animation=1") != -1 )
{
t.hover(function(){
// on hover
$(this).attr('src', 'libraries/phpthumb/phpThumbYT.php?w=131&h=92&far=C&iar=1&sfn=3&zc=C&f=gif&src=http://slovoprekazdeho.sk/media/'+media_id+'/preview.gif');
}, function(){
// on rollout
$(this).attr('src', src1);
});
}
});
Post a Comment for "Jquery.attr('src') Replace Not Working In Ff"