Home > Web Front-end > JS Tutorial > js检测网络是否具体连接功能的代码_javascript技巧

js检测网络是否具体连接功能的代码_javascript技巧

WBOY
Release: 2016-05-16 16:47:08
Original
1466 people have browsed it
复制代码 代码如下:

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('你的电脑没有链接网络,连接上网络后才能打开地图!');
});
document.body.appendChild(dom);
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template