Window. history. back ().
Problems caused by window. history. back ()
Prepared by: CC Dad
Today, I would like to share with you the introduction of windows. history. back () issues, the author encountered a variety of different situations in actual development, here to make a summary for reference. If you are interested, you can discuss and learn it together. Otherwise, you can skip it.
1.SinceWebDevelopment, often usedHtmlControl, so it is quite simple to process
Use either of the following methods:
Window. history. back (); (not refreshed)
Window. location. href = 'previous page. aspx '(refresh)
<Input type = button value = Refresh onclick = "window. location. reload ()">
<Input type = button value = forward onclick = "window. history. go (1)">
<Input type = button value = backward onclick = "window. history. go (-1)">
<Input type = button value = forward onclick = "window. history. forward ()">
<Input type = button value = backward onclick = "window. history. back ()">
Back + refresh
<Input type = button value = backward onclick = "window. history. go (-1); window. location. reload ()">
2.But goWebcontrolThis is not universal. After testing, we found that the following operations should be performed:(Pay attention to the red part):
<Asp: Button ID = "btnBack" Width = "80px" runat = "server" Text = "Back" OnClientClick = "window. history. back (); return false; "> (not refreshed)
<Asp: Button ID = "btnBack" Width = "80px" runat = "server" Text = "Back" OnClientClick = "window. location = 'P _ PRQuoList. aspx '; return false; "> (refresh)
<Asp: Button ID = "btnBack" Width = "80px" runat = "server" Text = "Back" OnClientClick = "window. location. href = document. referrer; return false; ">
</Asp: Button> (refresh)
3.InC # WebIn the program, for example, for the page button to write back the Previous Page code
This. RegisterClientScriptBlock ("E", "<script language = javascript> history. go (-2); </script> ");
Among them, history. go (-2) should be written as-2. Because the page has been refreshed once before the button event is triggered, it should be-2.
Response. Write ("<script language = javascript> history. go (-2); </script> ");
It must also be written as "-2 ". It is different from writing scripts directly. History. back () is the previous page
I = 1
History. go (I) goes to a specified page
4.In addition, when we return a message, we want to retain the content of the previous input and how to handle it. In general, the returned content is cleared.
On the Internet, the. history. back (-1); cannot be removed. Use window. location. href = 'page. aspx ';
The following are common solutions:
<HTML> <HEAD>
<META content = history name = save>
<STYLE>
. SaveHistory {behavior: url (# default # savehistory );}
</STYLE>
<META content = "MSHTML 6.00.2800.1528" name = GENERATOR> </HEAD>
<BODY> added the history retention function: <BR> <TEXTAREA class = saveHistory> </TEXTAREA> <BR> not added: <BR> <TEXTAREA> </TEXTAREA>
<P> <INPUT onclick = 'javascript: location. href = "http://www.google.com" 'Type = button value = click to enter, and then press the back key to try?> </P> </BODY> </HTML>
The second part is the solution I used in the program.
Join the technology sharing Group
The following is an article summarized by other netizens, which is well-written and excerpted for your reference.
Http://blog.csdn.net/durendong/article/details/9245863
To open a jsp page, you must have refreshed it using a client script.
How to refresh the page with Javascript:
1 history. go (0)
2 location. reload ()
3 location = location
4 location. assign (location)
5 document.exe cCommand ('refresh ')
6 window. navigate (location)
7 location. replace (location)
8 document. URL = location. href