Home  >  Article  >  Web Front-end  >  Use js to determine whether the client can access the Internet (code attached)

Use js to determine whether the client can access the Internet (code attached)

亚连
亚连Original
2018-05-18 09:38:581586browse

The following is the js I compiled for you to use to determine whether the client can access the Internet. Interested students can take a look.

The first type:

<script src=" 
<script language="javascript" type="text/javascript">   
if(!window.jQuery)
{
  alert("能上网");    
}else{
  alert("不能上网");
}
</script>

The second type:

Use js to do cross-domain

  $.getScript("http://api.taobao.com/apitools/ajax_props.do?act=props&cid=50000436&restBool=false", 
  function () {
        //放一些只有上网才能做的代码
        }
  );

or

//跨域(可跨所有域名)    
$.getJSON("http://e.hnce.com.cn/tools/ajax.aspx?jsoncallback=?", { id: 0, action: &#39;jobcategoryjson&#39; }, 
function(json) {
         alert(json[0].pid);        
         alert(json[0].items[0]._name);
             });

The above is the js I compiled for you to use to determine whether the client can access the Internet. I hope it will be helpful to everyone in the future.

Related articles:

Interview questions about AJAX (with answers)

Detailed analysis of the use of AJAX for you Method (code pasted)

Detailed interpretation of the code, string connection in Javascript

The above is the detailed content of Use js to determine whether the client can access the Internet (code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn