Javascript code for checking network connection function-javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how js can detect whether the network is connected to a specific function. For more information, see The Code is as follows:


Var EventUtil = {
AddHandler: function (element, type, handler ){
If (element. addEventListener ){
Element. addEventListener (type, handler, false );
} Else if (element. attachEvent ){
Element. attachEvent ("on" + type, handler );
} Else {
Element ["on" + type] = handler;
}
},
RemoveHandler: function (element, type, handler ){
If (element. removeEventListener ){
Element. removeEventListener (type, handler, false );
} Else if (element. detachEvent ){
Element. detachEvent ("on" + type, handler );
} Else {
Element ["on" + type] = null;
}
}
};

Var dom = document. createElement ('img ');
Dom. style = 'display: none ;';
Dom. src = 'HTTP: // www.baidu.com/img/bdlogo.gif ';
Dom. id = 'map _ img ';
EventUtil. addHandler (dom, 'error', function (){

Alert ('the network is not connected to your computer. You can open the map only after you connect to the network! ');
});
Document. body. appendChild (dom );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.