Refreshing a page with JavaScript in Firefox - Stack Overflow

I'm currently working on this really simple text based game and to play again, you have to refresh

I'm currently working on this really simple text based game and to play again, you have to refresh the page. This seems to work in Opera and Chrome, but it's not resetting the page in Firefox. Here is the function I'm using.

$(function() {
    $('#play_again').click(function() {
        var answer = confirm ("Reset the game?")
        if (answer) {
        window.location.reload(); 
        }
    });
});

I think Firefox is caching the page or something. How could I make this work?

I'm currently working on this really simple text based game and to play again, you have to refresh the page. This seems to work in Opera and Chrome, but it's not resetting the page in Firefox. Here is the function I'm using.

$(function() {
    $('#play_again').click(function() {
        var answer = confirm ("Reset the game?")
        if (answer) {
        window.location.reload(); 
        }
    });
});

I think Firefox is caching the page or something. How could I make this work?

Share Improve this question asked Apr 26, 2012 at 17:41 Jack DavisJack Davis 5954 gold badges11 silver badges17 bronze badges 3
  • try history.go(0) as i suggested in my answer ... – Pranay Rana Commented Apr 26, 2012 at 18:06
  • is it helpful for you ???????????? – Pranay Rana Commented Apr 26, 2012 at 18:53
  • I ended up using Jakob's answer, but thanks. – Jack Davis Commented Apr 28, 2012 at 19:57
Add a ment  | 

4 Answers 4

Reset to default 4

Instead of using window.location.href, I suggest using window.location.replace. Why? Because href will add a new entry to the browser history. This may not be the behavior you're expecting.

window.location.replace( window.location.href )

this is something that's hard to do, but you can trick IE's and firefox's cache into thinking it's a new page by adding a random querystring. Can you try something like

window.location.href = window.location.href + '?refresh';

Try

$(function () {
    $('#play_again').click(function () {
        var answer = confirm("Reset the game?")
        if (answer) {
            $("form").each(function () {
                this.reset();
            });
            window.location.reload();
        }
    });
});

This works:

document.location=document.location;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744753182a4591721.html

相关推荐

  • Refreshing a page with JavaScript in Firefox - Stack Overflow

    I'm currently working on this really simple text based game and to play again, you have to refresh

    20小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信