如果没有互联网连接,请隐藏iframe [英] if there is no internet connection, hide iframe

查看:83
本文介绍了如果没有互联网连接,请隐藏iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iframe:

<iframe id="iframe" title="Environment Canada Weather" src="" allowtransparency="false" frameborder="0" height="170"></iframe>

jquery:

$( document ).ready(function() {
    window.setInterval(function(){
        if (navigator.onLine) {
            //$("#iframe").show();
            $("#iframe").attr("src", "http://weather.gc.ca/wxlink/wxlink.html?cityCode=on-143&amp;lang=e");
        }
        else{
            $("#iframe").hide();
        }
    }, 5000);
});

如果没有互联网连接,我无法隐藏iframe。我不知道这里有什么问题。
谢谢。

I am not able to hide iframe if there is no internet connection. I don't know what's wrong here. Thanks.

推荐答案

navigator.onLine 告诉您是否浏览器是否处于离线模式。

navigator.onLine tells you if the browser is in "offline" mode or not.

它实际上并不会检查您是否可以到达网络,正如您可能认为的那样。

It does not actually check if you can reach the net, as you probably think.

(为此,您可以尝试使用ajax ping Google.com,或者做一些类似的技巧)

(To do this, you could try to ping Google.com with ajax, or do some similar trick)

这篇关于如果没有互联网连接,请隐藏iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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