jquery在线Ping工具

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

 21.1K  0  查看评论 (0)
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文本文字符串中自动提取keywords关键字插件

一款自动提取关键词插件,自动忽略掉一些无关紧要的词语,自动提取关键字并列表显示出来,可复制。
  实用工具
 5807  0

javascript实现的高仿360桌面悬浮球插件

一款鼠标可随意拖拽移动的悬浮球插件,纯源生js手写 ,简单好用的仿360桌面悬浮球,可拖拽、自动贴边、自动适应屏幕。
  实用工具
 41035  0

javascript带验证功能的PIN码在线生成器

鼠标可点击“生成Pin”按钮生成一个随机的4位Pin码,它将显示在input字段中。然后使用提供的数字按钮输入PIN。该代码还允许您清除输入的PIN,并提供输入的PIN是否与生成的PIN匹配验证提示。
  实用工具
 11224  0

jquery支持自定义配置的在线生成随机密码插件

一款可自定义设置的密码生成工具插件,可配置:密码长度(进度滑块)、纯字母、纯数字、特殊符号等,可点击按钮复制密码。
  实用工具
 9861  0

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

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