search

Home  >  Q&A  >  body text

javascript - Determine user network environment

How does js determine whether the user's network is useful? That is, I want to determine whether the user can use the external network? And make sure he has access to the Internet? God, please help me. . .

阿神阿神2695 days ago1128

reply all(3)I'll reply

  • 三叔

    三叔2017-07-05 11:09:13

    Request an external network address in the background and see if it can be returned normally.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-07-05 11:09:13

    $.ajax({
        url: '/',
        success: res => alert('应该有网'),
        error: () => alert('应该没网')
    }); 

    Want to try it?

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-07-05 11:09:13

    You can use it directly, or learn from https://www.npmjs.com/package/ping

    reply
    0
  • Cancelreply