最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Non-looping Animated Gif won't replay on web page reload - Stack Overflow

programmeradmin1浏览0评论

I've created an animated gif that only plays once in Fireworks.

I've placed it on the webpage: .html

but if you refresh the page in Chrome or Firefox the gif doesn't play again.

My code is:

<!doctype html>

<html>
<head>
<meta charset="utf-8">
<title>Hollywood vs the Great Outdoors</title>

<style>
#case_1 {position:absolute;top:0px;left:0px;z-index:50;}
</style>
</head>

<body>

<div id="case_1"><img src="dvd_open_1.gif" /></div>

</body>
</html>

Can anyone please help? Kind regards Greg

I've created an animated gif that only plays once in Fireworks.

I've placed it on the webpage: http://www.mediaworks.co.uk/content-marketing/hollywood-survival/index.html

but if you refresh the page in Chrome or Firefox the gif doesn't play again.

My code is:

<!doctype html>

<html>
<head>
<meta charset="utf-8">
<title>Hollywood vs the Great Outdoors</title>

<style>
#case_1 {position:absolute;top:0px;left:0px;z-index:50;}
</style>
</head>

<body>

<div id="case_1"><img src="dvd_open_1.gif" /></div>

</body>
</html>

Can anyone please help? Kind regards Greg

Share asked Nov 4, 2013 at 11:04 user2840467user2840467 8933 gold badges13 silver badges20 bronze badges 1
  • Works on my end, so you should be good to go :). – user2704193 Commented Nov 4, 2013 at 11:36
Add a ment  | 

1 Answer 1

Reset to default 7

The reason why this happens is that the browser is caching the image..sort of.

<div id="case_1"><img id="image" src="dvd_open_1.gif" /></div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#image").attr("src", "dvd_open_1.gif?" + Math.random());
    });
</script>

Basically what this does is adding a random string ?randomNumberString which tricks the browser in thinking that it is different file.

p.s. you will need to include the jQuery lib into your file to use the jQuery(document).ready function.

发布评论

评论列表(0)

  1. 暂无评论