Home  >  Article  >  Web Front-end  >  Back and refresh implementation methods in javascript

Back and refresh implementation methods in javascript

高洛峰
高洛峰Original
2016-12-07 11:11:341099browse

<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()"> 后退+刷新<input type=button value=后退 onclick="window.history.go(-1);window.location.reload()">

In a C# Web program, if you write code to return to the previous page for a page button

this.RegisterClientScriptBlock("E", "a2bbbb160e7164ddd930eed2a74569d1history.go(-2);9429d6e1efad07153846e528605c447e");

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

Response.Write("cb07111ca5ae5ef678bbf0d01d0237c0history.go(-2);2cacc6d41bbb37262a98f745aa00fbf0");

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, which is equivalent to IE Forward and backward functions.

The specific use depends on when you need it. For example, the verification during user registration 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();
     }
   }
}

Open a jsp page, it must be refreshed with 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('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href


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