


Clicking the browser's back button will refresh the history page. Solution to this problem
First of all, we know how this problem occurs. If we have the following page list information page, click to enter the details page, modify the data on the details page and return it through history, and then return to the list information page, because the list information is a history return Yes, the original data before modification is still displayed by default, and the modified data needs to be refreshed. So, is there any way for us to refresh the data in the previous history page by clicking the return button on the mobile phone?
onpageshow event and onload event. The onpageshow event is similar to the onload event. The onload event is triggered when the page is loaded for the first time. The onpageshow event is triggered every time the page is loaded. That is, the onload event is not triggered when the page is read from the browser cache.
To see whether the page was loaded directly from the server or read from the cache, you can use the persisted attribute of the PageTransitionEvent object to determine. If the page reads this attribute from the browser's cache, it returns true, otherwise it returns false
Solution
By onload method
The code is as follows:
Write a hidden input in the page
<input type="hidden" id="refreshed" value="no">
js operation is as follows
onload=function(){ var refreshedId=document.getElementById("refreshed"); if(refreshedId.value=="no"){ refreshedId.value="yes"; } else{ refreshedId.value="no"; location.reload(); } }
Through onpageshow method
This method is no problem on the computer, but it does not return in Apple Safari To execute the onload event, use the following method:
window.onpageshow = function(event) { if (event.persisted) { window.location.reload() } };
Through actual operation, we found that event.persisted always returns false on the computer, but there is no problem on the mobile phone safari.
Comprehensive solution
Therefore, you can write the code as follows:
if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) { window.onpageshow = function(event) { if (event.persisted) { window.location.reload() } }; }else{ onload=function(){ var refreshedId=document.getElementById("refreshed"); if(refreshedId.value=="no"){ refreshedId.value="yes"; } else{ refreshedId.value="no"; location.reload(); } } }
Through the above code, I found that when the page is opened for the first time in Safari, sometimes a splash screen will appear. Effect.
Add the following code:
$(window).bind("unload", function() { });
The splash screen effect will no longer appear.
Prevent caching through iframe
Add the following code to the page
<iframe style="height:0px;width:0px;visibility:hidden" src="about:blank"> this prevents back forward cache </iframe>
This method needs to be verified.
By TimestampForced refresh method
The following code is for the safari return button problem in iPad
var showLoadingBoxSetIntervalVar; var showLoadingBoxCount = 0; var showLoadingBoxLoadedTimestamp = 0 function showLoadingBox(text) { var showLoadingBoxSetIntervalVar=self.setInterval(function(){showLoadingBoxIpadRelaod()},1000); showLoadingBoxCount = 0 showLoadingBoxLoadedTimestamp = new Date().getTime(); //Here load the spinner } function showLoadingBoxIpadRelaod() { //计算时间超过500毫秒 var diffTime = ( (new Date().getTime()) - showLoadingBoxLoadedTimestamp - 500)/1000; showLoadingBoxCount = showLoadingBoxCount + 1; var isiPad = navigator.userAgent.match(/iPad/i) != null; if(diffTime > showLoadingBoxCount && isiPad){ location.reload(); } }
I believe you have mastered it after reading these cases Method, for more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
css3 click to display ripple effects
How to use canvas to create the effect of particle fountain animation
The above is the detailed content of Clicking the browser's back button will refresh the history page. Solution to this problem. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The browser's unresponsive method after the WebSocket server returns 401. When using Netty to develop a WebSocket server, you often encounter the need to verify the token. �...

The steps to register an Ouyi account are as follows: 1. Prepare a valid email or mobile phone number and stabilize the network. 2. Visit Ouyi’s official website. 3. Enter the registration page. 4. Select email or mobile phone number to register and fill in the information. 5. Obtain and fill in the verification code. 6. Agree to the user agreement. 7. Complete registration and log in, carry out KYC and set up security measures.

To safely download the Binance APP, you need to go through the official channels: 1. Visit the Binance official website, 2. Find and click the APP download portal, 3. Choose to scan the QR code, app store, or directly download the APK file to download to ensure that the link and developer information are authentic, and enable two-factor verification to protect the security of the account.

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

Generating a WeChat applet QR code with parameters in Java and displaying it on an HTML page is a common requirement. This article will discuss in detail how to use J...

Confusion and answers about JWT and Session Many beginners are often confused about their nature and applicable scenarios when learning JWT and Session. This article will revolve around J...

After the USDT transfer address is incorrect, first confirm that the transfer has occurred, and then take measures according to the error type. 1. Confirm the transfer: view the transaction history, obtain and query the transaction hash value on the blockchain browser. 2. Take measures: If the address does not exist, wait for the funds to be returned or contact customer service; if it is an invalid address, contact customer service and seek professional help; if it is transferred to someone else, try to contact the payee or seek legal help.
