Current location - Music Encyclopedia - Chinese History - How to change the previous page in the history webpage into another page in js?
How to change the previous page in the history webpage into another page in js?
Js did not change the browsing history url, but obtained the url address from the previous page. You can use window.location.replace (URL); To reset the browsing history,

Window.location.replace does not save the URL before the browser jumps, so pressing Enter will be invalid;

Example:

There are three jsp pages (1.jsp, 2.jsp, 3.jsp), and the default entry is 1. JSP。 When I entered 3.jsp, I used window.location.replace ("3.jsp") in 3.jsp. Use window.location.href ("3.jsp"); There is no difference with the user interface, but when the 3.jsp page has a "back" button, call window.history.go (-1); wondow . history . back(); Method, click the back button to return to the 3.jsp page, and the difference will come out. When using window.location.replace("3.jsp "); If you are connected to 3.jsp page, call window.history.go (-1) in 3.jsp page; wondow . history . back(); The method is not easy to use. When using window.location.href("3.jsp "),1.jsp will be returned; "); If you are connected to 3.jsp page, call window.history.go (-1) in 3.jsp page; wondow . history . back(); This method is easy to use and will be returned to 2.jsp. Because window.location.replace ("3.jsp"); Is a jump that does not send a request to the server, while window.history.go (-1); wondow . history . back(); The method decides which page to jump to according to the request recorded by the server, so it will jump to the system default page1.jsp.window.location.href ("3.jsp"); Is a jump to send a request to the server, window.history.go (-1); wondow . history . back(); The method is to decide which page to jump to according to the request recorded by the server, so that you can return to 2.jsp.