How does the front end determine whether the user's network can access the Internet? Because some users cannot have an internal network without an external network, so if they want to detect those who cannot access the Internet, they can cancel the connection to the external link. Can anyone with experience give me a way to judge~~~
Demo~~
Just find a picture, such as the baidu logo below, and test whether the picture can be opened
Request Baidu. If successful, it means there is an external network.
You can write an onerror directly in the script, <script src="1.js" onerror="method (process in this method...)"></script> If it cannot be loaded, it means there is a problem with the network
https://github.com/alfg/ping....
It is directly packaged and can be used as soon as you get it. The author of the question will divide and post it.
navigator.onLine, detect network connection
Just pull Baidu homepage with ajax
https://developer.mozilla.org...
Before asking questions, you should make good use of search engines. You can directly search for "JavaScript Network" on sf to get the results you want.
js determines whether the network is disconnected
The script cannot be loaded when the Internet is not available. How to judge? You got the wrong relationship