Home > Web Front-end > JS Tutorial > Detailed examples of back and refresh in JavaScript

Detailed examples of back and refresh in JavaScript

黄舟
Release: 2017-12-04 13:41:22
Original
2050 people have browsed it

Whether we are learning JavaScript or in our daily development, the back and refresh functions have always been encountered, all for a better user experience, so we will give it to you today Introducing detailed examples of back and refresh in JavaScript!

<input type=button value=刷新 onclick="window.location.reload()">
<input type=button value=前进 onclick="window.history.go(1)">
<input type=button value=后退 onclick="window.history.go(-1)">
<input type=button value=前进 onclick="window.history.forward()">
<input type=button value=后退 onclick="window.history.back()">
Copy after login

Back+Refresh In a C# Web program, if Write the page button Return to the previous pageCode

this.RegisterClientScriptBlock("E", "<script language=javascript>history.go(-2);</script>");
Copy after login

Among them, history.go(-2) should be written as -2, because it has been refreshed once before the button event is triggered. page, so it should be -2.

Response.Write("<script language=javascript>history.go(-2);</script>");
Copy after login

Also write "-2" here. It is different from writing scripts directly. history.back() is to go to the previous page
i=1
history.go(i) to a specified page
If it is history.go(0), it is to refresh these two JS codes , equivalent to the forward and backward functions of IE.
The specific use depends on when you need it. For example, the verification when user registers is background verification. This can be used when the requirements are not met, which can minimize the need for users to repeatedly enter data.
For example: Loading page:

function onLoadPage(){
     if(event.srcElement.tagName=="SPAN"){
         oFrame=top.window.middle.frames[2];
         oTxt=event.srcElement.innerText;
         switch(oTxt){
             case "前 进":
                 oFrame.history.go(1);
             case "后 退":
                 oFrame.history.back();
             case "刷 新":
                 oFrame.location.reload();
         }
     }
}
Copy after login

When opening a jsp page, it must be refreshed with a client script.
Several ways to refresh the page in Javascript:

1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand(&#39;Refresh&#39;)
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
Copy after login

Summary:

This article introduces to you about JavaScript with examples I believe everyone has a certain understanding of the back and refresh in this topic. I hope it will be helpful to your work!

Related recommendations:

The browser page goes back, how to re-run ajax

Detailed explanation of js banning the browser page back function example

Implementing js disabling the Backspace key to make the browser go back

The above is the detailed content of Detailed examples of back and refresh in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template