Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

javascript - how to force page refresh on browser back click?

Is there a cross-browser compatible way of forcing page refresh when clicking the navigator back button?

i am trying to access to actualised cookies :

i have a js setcookie function that record changes in a type selector

$( "#type-select" ).change(function() {             
    var type = $("#type-select").val();
    SetCookie("liste-voyage-type",type);
    });

i'd like to retrieve that value when returning on this page, clicking the browser back button, using php

 if (isset($_COOKIE["liste-voyage-type"]))
        $type=$_COOKIE["liste-voyage-type"];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had a similar requirement in my project. You can do something like this:

For example, lets say there are two pages: page1 and page2

In Page1 do something like this:

<script>
     if (sessionStorage.getItem("Page2Visited")) {
          sessionStorage.removeItem("Page2Visited");
          window.location.reload(true); // force refresh page1
     }
</script>

And in page2:

<script>
     sessionStorage.setItem("Page2Visited", "True");
</script>

Now, it will force a page refresh on page1, whenever you click back button from page2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...