简体   繁体   English

Web浏览器控件,检测Internet连接

[英]Webbrowser control , Detect internet connection

Here is my code scenario, I display html page in webbrowser control. 这是我的代码方案,我在webbrowser控件中显示html页面。 The content will be loaded from some RSS url dynamically (used JQuery to load the content from URL) and displayed in WB. 内容将从一些RSS URL动态加载(使用JQuery从URL加载内容)并显示在WB中。 My problem is, i have to check for the "Internet Connectivity" when a loop is completed by scrolling text. 我的问题是,当通过滚动文本完成循环时,我必须检查“ Internet连接”。 I tried using "navigator.onLine", which is working well in html page but not working when loaded into the Web browser control, it returned "true" even internet disconnected. 我尝试使用“ navigator.onLine”,它在html页面中运行良好,但在加载到Web浏览器控件中时却无法运行,即使互联网断开,它也返回“ true”。

The jQuery ajax method lets you define an error callback, which should get hit if the user has dropped his connection (or for other reasons)... jQuery ajax方法可让您定义错误回调,如果用户断开连接(或出于其他原因),该回调将被点击...

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  },
  error: function(XMLHttpRequest, textStatus, errorThrown){
    alert("oh crap, an error: " + textStatus);
  }
});

For more info: http://api.jquery.com/jQuery.ajax/ 有关更多信息: http : //api.jquery.com/jQuery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM