JavaScript tips: js go back to the previous page and refresh

Alibaba Cloud
4 min readJan 25, 2022

1: JS overloaded page, local refresh, back to the previous page
code as follows:

<a href= “Javascript:history.go ( -1)” > Return to Previous page </a>
<a href= “Javascript:location.reload ()” > overloaded page, local refresh </a>
<a href= “Javascript:history.go ( -1); Location.reload ()” > Return to the previous page overloaded page, local refresh </a>

Return the first two pages and refresh the JS code should be how to write.

code as follows:

History.go (-2);
Location.reload ();

2: Js method
code as follows:

<a href= “#” onclick= “Self.location=document.referrer;” > Return </a>

Methods that the ASP automatically returns and refreshes:

code as follows:

Response. Write (“<script language=javascript>self.location=document.referrer;</script>”)

Typically used to submit an action to a page and return to the previous page and refresh!

1. Javascript returns to the previous page history.go (-1) and returns two pages: History.go (-2);
2. History.back ().
3. Window.history.forward () Back to next page
4. Window.history.go (returns the first few pages, also can use the visited URL)

Cases:
<a href= “Javascript:history.go (-1);” > Up one page </a>

Response. Write (“<script language=javascript>”)
Response. Write (“If” (!confirm (‘ Complete task? ‘)) {History.back ();} “)
Response. Write (“</script>”)
Response. Write (“<script language=javascript>history.go ( -1);</script>”)
<a href= “Javascript:history.go (-1);” > Up one page </a>

Page Jump: onclick= “window.location.href= ‘ list.aspx ‘“
P.S.
Tips (JS reference js):
<script type=text/javascript>
<! —
if (typeof swfobject = = “undefined”) {
document.write (‘ <scr ‘ + ‘ IPT type= “Text/javascript” src= “/scripts/swfobject-1.5.js” ></scr ‘ + ‘ ipt> ‘);}

</script>

JavaScript refreshes the page in several ways:

history.go (0)
Location.reload ()
location=location
Location.assign (location)
Document.execcommand (‘ Refresh ‘)
Window.navigate (location)
Location.replace (location)
document. Url=location.href

Ways to automatically refresh pages:
1. Page Automatic refresh: Add the following code to the <meta http-equiv= “Refresh” content= “>”
20 of which means that the page is refreshed every 20 seconds.

2. Page Automatic Jump: Add the following code to the <meta http-equiv= “Refresh” content= “20;url=http://www.javaeye.com" >
20 of which refers to 20 seconds after the jump to the http://www.javaeye.com page

3. Page automatically refresh JS version
<script language= “JavaScript” >
function Myrefresh ()
{
Window.location.reload ();
}
SetTimeout (‘ Myrefresh () ‘, 1000); Specify 1 seconds to refresh once
</script>

ASP. NET how to output refresh the parent window script Statement
1. this.response.write (“<script>opener.location.reload ();</script>” );
2. this.response.write (“<script>opener.window.location.href = Opener.window.location.href; </script> “);
3. Response.Write (“<script language=javascript>opener.window.navigate (“ the page you want to refresh. asp “);< /script> “)

JS Refresh Frame Script statement

How to refresh the page that contains the frame with
<script language=javascript>
Parent.location.reload ();
</script>

child window refreshes parent window
<script language=javascript>
Self.opener.location.reload ();
</script>
(or <a href= “javascript:opener.location.reload ()” > Refresh </a>)

How to refresh another frame’s page with
<script language=javascript>
Parent. Another FrameID.location.reload ();
</script>

If you want to close the window or refresh when you want to open windows, call the following statement in <body>.

<body onload= “Opener.location.reload ()” > Refresh when opening windows
<body onunload= “Opener.location.reload ()” > Refresh when closed

<script language= “JavaScript” >
Window.opener.document.location.reload ()
</script>

3: In the ASP using JS implementation to return to the previous page and refresh

Using JS in ASP to return to the previous page and refresh I would like to use ASP to develop the site often used. But there are several ways to do it, but the purpose is the same.

code as follows:

<%
Response.Write (“<font color=” “Red” “font-size=” “12px” “> has been deleted successfully! Font> “)
%>
<div align= “center” >[<a href= “/” onclick= “Javascript:window.history.go ( -1); return false;” Class=fontsize14 ><span style= “color: #CC0033” > Return </span></a>]</div>
The function of this code is to tell the user if the implementation of the function has been achieved, but in return, it is best to refresh the original page so that the new information displayed or let the deleted things are not displayed. But this code cannot refresh the original page when it returns.
So you need to add such a piece of code to the original page:
<script>
if (window.name!= “Bencalie”) {
If the page’s Name property is not the specified name, refresh it
Location.reload ();
Window.name = “Bencalie”;
}
else{
If the Name property of the page is specified, do nothing and avoid constant refresh
Window.name = “”;
}
</script>

So we can achieve our goal — return to the previous page and refresh.
Of course, there is simpler code than this, response.write”<script>alert(‘Delete successful!’);window.location=’Original page’’;</script>”

Original Source:

--

--

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com