检查是否连接到网络; jQuery的 [英] Check if connected to a network; jQuery

查看:125
本文介绍了检查是否连接到网络; jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过StackOverflow进行了搜索,并且已经看到了有关如何执行此操作的各种主题,但没有涉及到我的特定情况。我正在编写一个移动应用程序(使用HTML5,CSS,jQuery)。它最终将成为一个独立的应用程序,它将包含所有所需文件的本地副本。在我的一个页面上我有一个提交表单,并且由于用户无法在离线状态下提交表单,我希望该页面被重定向到一个自定义的404页面。

我只是在寻找是否有办法在jQuery中实现这一点,因为我还没有发现任何东西。



谢谢

解决方案

你可以使用

  if(navigator.onLine){
//我在线提交表单。
}


I have searched through StackOverflow and have seen various topics on how to do this, but nothing that really pertains to my particular situation. I am writing (for a class) a mobile "application" (using HTML5, CSS, jQuery). It will end up being a stand alone "app", something that will contain a local copy of all the needed files. On one of my pages I have a submit form, and since the user can't submit the form if they are offline, I would like the page to be redirected to a custom 404 page.

I was just searching to see if there was a way to accomplish this in jQuery, as I haven't really found anything yet.

Thanks

解决方案

You could use

if (navigator.onLine) {
    // I'm online so submit the form.
}

这篇关于检查是否连接到网络; jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆