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

Detailed examples of back and refresh in JavaScript

黄舟
黄舟Original
2017-12-04 13:41:222000browse

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()">

Back+Refresh622c546399691f6d260da612c2cd416e 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>");

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

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

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

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!

Statement:
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