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"];
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.
i did it slighty differently with cookies
function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
if (getCookie('first_load'))
{
if (getCookie('first_load')==true)
{
window.location.reload(true); // force refresh page-liste
SetCookie("first_load",false);
}
}
SetCookie("first_load",true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With