Gislef
Gislef

Reputation: 1637

Reload/refresh image dont work

I am automatically generating images, but the file with the same name is updated but not have browser updates

$("#imagem_teste").attr("src", data)

I try:

d = new Date();
$("#imagem_teste").attr("src", data+d.getTime());

,

$("#imagem_teste").attr("src", data + new Date().getTime());

,

$("#imagem_teste").removeAttr("src").attr("src", data);

and

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

But still can not solve.

Thank help

Upvotes: 1

Views: 112

Answers (1)

Shyju
Shyju

Reputation: 218732

You can execute this code to set a unique image source on some event. It is reading the existing src attribute value and appending a unique timestamp.

var name = $("#imagem_teste").attr("src");
name = name + '?'+$.now();
$("#imagem_teste").attr("src", name);

$.now() method generates a unique timestamp and is a shorthand for the number returned by the expression (new Date).getTime()

Working sample here

Upvotes: 2

Related Questions