简体   繁体   English

用户单击浏览器的后退按钮时如何重新加载当前页面

[英]How to reload current page when user click back button of browser

Can i reload the current page when user click back button. 用户单击后退按钮时,我可以重新加载当前页面吗? I will give you a background of my problem to know the reason why I want to do this. 我将给您介绍我的问题的背景,以了解我为什么要这样做。 I have an asp.net web application 3.5 framework that display generated pdf file to an ajax modalpop. 我有一个asp.net Web应用程序3.5框架,该框架将生成的pdf文件显示为ajax modalpop。 Doing this task is not easy as it was due to some cross browser issues that i've encounter and manage to handle all of those and only left me with this single problem. 执行此任务并不容易,因为这是由于遇到了一些跨浏览器问题,并且设法处理了所有这些问题,而使我只剩下一个问题。 I manage to display pdf file on an iframe within the ajax modalpopup and this setup is compatible with Chrome, Firefox, Safari and Opera but not on IE. 我设法在ajax modalpopup的iframe中显示pdf文件,并且此设置与Chrome,Firefox,Safari和Opera兼容,但在IE上不兼容。 I manage to found a solution on IE9 64bit using response.binarywrite and pdf file will display on a new instance of Adobe Acrobat Reader (v11 and v10) but on IE9 32bit this is not how it renders pdf, it renders on the current page itself and I don't want to be that way and when user click on the back button of the browser it will redirect to the last page visited not on the page where I click a button to display the pdf. 我设法使用response.binarywrite和pdf文件在IE9 64bit上找到了一个解决方案,它将显示在Adobe Acrobat Reader的新实例(v11和v10)上,但是在IE9 32bit上,这不是它呈现pdf的方式,而是在当前页面上呈现而且我也不想那样,当用户单击浏览器的后退按钮时,它将重定向到上次访问的页面,而不是我单击按钮以显示pdf的页面上。 I'm aware that by looking on the browser it still on the current page where the trigger to load the pdf happens. 我知道,通过在浏览器上查看它,仍然会在当前页面上发生触发加载pdf的事件。 Now is it possible to reload the current page by clicking the back button and will it reload on the page where the pdf file is not visible. 现在可以通过单击“后退”按钮重新加载当前页面,并将其重新加载到看不到pdf文件的页面上。 Refer to the code below to what I've done so far. 请参阅下面的代码以了解到目前为止的操作。

<script type="text/javascript">
  window.onunload = function {
     alert(document.URL);
     window.location = document.URL;
     window.history.go(-1);
  }
</script>

alert box prompt when I try to back on the browser but the code below does not execute, maybe it was executed but there is not effect on the page. 提示框提示,当我尝试返回浏览器但以下代码未执行时,可能已执行,但对页面无效。 Please I really need help thanks in advance. 请我真的需要帮助,谢谢。

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);

I do not completely understand what you are trying to achieve but a possible solution would be to send the user initially to an html page that is there for the only purpose of rerouting the user to the desired page. 我不完全理解您要实现的目标,但是可能的解决方案是将用户最初发送到html页面,该页面的唯一目的是将用户重新路由到所需页面。 When they click the back button it would bring them to this rerouting html page, essentially putting them in a loop. 当他们单击“后退”按钮时,会将他们带到此重新路由的html页面,本质上将它们置于循环中。

I am using this technique .. 我正在使用这种技术..

 angular.element(document).ready(function() { var State = History.getState(); //........ now use State variable }); 

Hope this will help you. 希望这会帮助你。 :-) :-)

here: 这里:

<script>    
history.pushState(null, null, document.URL);
   window.addEventListener('popstate', function () {
   history.pushState(null, null, document.URL);
   location.reload();
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM