A small example of a Javascript implementation that returns to the previous page and refreshes

  • 2020-03-30 00:49:33
  • OfStack

Today, I wrote a small hint of a successful page, at the same time, I asked to return to the previous page, and realized the operation of the previous page to refresh (such as deleted, added), searched on the Internet, basically 90% of it is said to use window.history.go(-1), or use window.history.back(-1), and some said child page to refresh the parent page


<script language=JavaScript>
    self.opener.location.reload();
</script>

After the test in the JSP page, in the operation page selected to add the item after clicking the button to save and then skip to the success of the prompt page to return to find that there is no refresh, manual refresh after the display, for those paste copy technology is not tested article is really sad.

In fact, for this technology, I did not find it completely dependent on JS implementation, one idea is to make the previous page is not cache, read out every time on the line (other people's ideas, I do not understand the specific principle)

The implementation of JSP is as follows:

  Reply - text mb10 code


<SPAN style="FONT-SIZE: 18px; BACKGROUND-COLOR: #ffffff">
<SPAN style="FONT-FAMILY: 'Microsoft YaHei'; COLOR: #3333ff">
<STRONG>
<%String rec = request.getHeader("REFERER");%>   
    <input type="button" onclick="javascript:window.location='<%=ref%>'">   
</STRONG>
</SPAN>
</SPAN>  
<%String rec = request.getHeader("REFERER");%>
    <input type="button" onclick="javascript:window.location='<%=ref%>'">

The realization method of ASP page is as follows:


<%' Gets the address of the previous page 
 address = request.ServerVariables("HTTP_REFERER")
%>
<!--window.location Has the effect of returning relative pages and refreshing them -->
<a href="javascript:window.location.href='<%=address%>'" style="cursor:hand"> return </a>

Reply - text mb10 code


<SPAN style="FONT-SIZE: 18px; BACKGROUND-COLOR: #ffffff"><SPAN style="FONT-FAMILY: 'Microsoft YaHei'; COLOR: #3333ff"><STRONG>. in servlet In the    
    request.getRequestDispatcher(request.getHeader("referer")).forward(request,response);   
     or    
    request.getRequestURL();   

</STRONG></SPAN></SPAN>


Related articles: