I want to know the network status using JavaScript,for example, if I plug out the network cable, there will be a pop up dialog to warn me this thing.
Asked
Active
Viewed 2,264 times
1 Answers
3
Native JavaScript cannot know the connection status. It depends on the host environment providing the data, which it generally does by asking the operating system's network stack.
In modern browsers, that information will be exposed through navigator.onLine

Quentin
- 914,110
- 126
- 1,211
- 1,335
-
2Though note that `navigator.onLine` only tells you if the system is connected to any network or not. It won't tell you if it is connected to the internet or not. – Derek 朕會功夫 Sep 11 '14 at 13:32