FireFox & IE Jquery not working

Go To StackoverFlow.com

0

I have created PHP GD image for captcha, file called image.php each time it generates a dynamic captcha image.


In signup.php I have

<img alt="" src="image.php"> 
<input type="button" id="btn" value="cant read captcha">
<!--btn is to load another captcha-->

jscript.js

$("#btn").click(function(){  
    $("img").attr('src','image.php');
});

Works in Chrome, Safari, and Opera but not in IE and Firefox.

How can I fix this or are there any alternative solutions?

2012-04-05 18:45
by Fakhr Alam
Why is your javascript in a string in your js file - Gabe 2012-04-05 19:00


0

$("image").attr("src","image.php?timestamp=" + new Date().getTime());


I think it was an issue of caching
firefox and ie does not pick image from source again and again
but it loads from its cache
by changing name of image it is now working for me in all browsers
thanx every one

2012-04-06 04:53
by Fakhr Alam


3

Is the code running after the dom loads? If not, try:

$(function(){
  $("#btn").click(function(){ 
    $("img").attr('src','image.php');  
  });
});

Is there an error in your console?

2012-04-05 18:59
by Cal
$(function(){ $("#btn").click(function(){ $("img").attr('src','image.php');
alert(9);//works in all browsers }); }) - Fakhr Alam 2012-04-06 04:42


2

Try a adding random number at the end of the url , this might be cache issue e.g

$("#btn").click(function(){  
    $(this).prev("img").attr('src','image.php?rnd='+Math.random());
});
2012-04-05 19:12
by sakhunzai
$("#captcha").attr("src","php/image33.php?timestamp=" + new Date().getTime()); worked for m - Fakhr Alam 2012-04-06 04:49
good to hear , please accept on of the answer which works for yo - sakhunzai 2012-04-06 04:56
Math.random()... It helped someone!! - Eamorr 2012-11-01 21:26


1

Maybe try this approach of adding a query string to prevent the browser caching.

How to reload/refresh an element(image) in jQuery

2012-04-05 19:06
by Paul


1

Try this code

$(function(){

  $("#btn").live("click",function(){ 

       $("img").attr('src','image.php');  

  });
});
2012-04-05 19:08
by Mahipal
Ads