jquery在线Ping工具

所属分类: 网页特效-实用工具    2024-12-29 01:44:41

jquery在线Ping工具 ie兼容9
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery在线Ping工具(共3个文件)

    • index.html

使用方法

/**
 * Creates a Ping instance.
 * @returns {Ping}
 * @constructor
 */
var Ping = function(opt) {
    this.opt = opt || {};
    this.favicon = this.opt.favicon || "/favicon.ico";
    this.timeout = this.opt.timeout || 0;
    this.logError = this.opt.logError || false;
};

/**
 * Pings source and triggers a callback when completed.
 * @param source Source of the website or server, including protocol and port.
 * @param callback Callback function to trigger when completed. Returns error and ping value.
 * @param timeout Optional number of milliseconds to wait before aborting.
 */
Ping.prototype.ping = function(source, callback) {
    var self = this;
    self.wasSuccess = false;
    self.img = new Image();
    self.img.onload = onload;
    self.img.onerror = onerror;

    var timer;
    var start = new Date();

    function onload(e) {
        self.wasSuccess = true;
        pingCheck.call(self, e);
    }

    function onerror(e) {
        self.wasSuccess = false;
        pingCheck.call(self, e);
    }

    if (self.timeout) {
        timer = setTimeout(function() {
            pingCheck.call(self, undefined);
    }, self.timeout); }


    /**
     * Times ping and triggers callback.
     */
    function pingCheck() {
        if (timer) { clearTimeout(timer); }
        var pong = new Date() - start;

        if (typeof callback === "function") {
            // When operating in timeout mode, the timeout callback doesn't pass [event] as e.
            // Notice [this] instead of [self], since .call() was used with context
            if (!this.wasSuccess) {
                if (self.logError) { console.error("error loading resource"); }
                return callback("error", pong);
            }
            return callback(null, pong);
        }
    }

    self.img.src = source + self.favicon + "?" + (+new Date()); // Trigger image load with cache buster
};

if (typeof exports !== "undefined") {
    if (typeof module !== "undefined" && module.exports) {
        module.exports = Ping;
    }
} else {
    window.Ping = Ping;
}

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 实用工具

jquery轻量级鼠标悬停自定义工具提示插件

jph-tooltip.js是一个轻量级工具提示插件,它可自动从元素的title或data tip属性中提取工具提示内容。当jQuery不可用或浏览器中禁用JavaScript时,自动返回到本机浏览器工具提示。
  实用工具
 4707  0

jquery点击触发下拉菜单可切换多语言页面内容插件

一款多国语言切换插件,通过从下拉列表中选择一个国家语言,可将页面文本内容翻译成不同的语言。
  实用工具
 91298  0

jquery在线图片人脸识别插件

一款人脸识别功能插件,使用该插件可很轻松的在照片中找到人物的面部,并用小方框定格在人物脸部位置。
  实用工具
 6575  0

jquery页面右下角浮动的whatsapp点击聊天插件

一个浮动和可自定义的Whatsapp按钮,鼠标悬停于按钮上,可触发弹出聊天对话窗口,可通过Whatsapp点击聊天。
  实用工具
 71326  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论