Dev-Tools检测脚本在mozilla firefox中无法正常工作

时间:2018-03-26 04:49:36

标签: javascript console mozilla

此代码用于检测dev-tools是否已打开。它在Opeara和Chrome中运行良好。但是在Mozilla Firefox中,这表示dev-tools实际上并不是开放的。{/ p>

我该如何解决这个问题?有什么建议吗?



(function(exportName) {
  var exports = exports || {};

  function create(options) {
    if (typeof options === "function") {
      options = {
        onchange: options
      };
    }
    options = options || {};
    var delay = options.delay || 500;
    var instance = {};
    instance.onchange = options.onchange;
    var checkStatus;
    var element = new Image();
    element.__defineGetter__("id", function() {
      setStatus("on");
    });
    var status = "unknown";

    function getStatus() {
      return status;
    }
    instance.getStatus = getStatus;

    function checkHandler() {
      if (
        window.Firebug &&
        window.Firebug.chrome &&
        window.Firebug.chrome.isInitialized
      ) {
        setStatus("on");
        return;
      }
      var r = /./;
      r.toString = function() {
        checkStatus = "DevTools on";
      };
      checkStatus = "DevTools off";
      console.log("%c", r, element);
      console.clear();
      setStatus(checkStatus);
    }

    function setStatus(value) {
      if (status !== value) {
        status = value;
        if (typeof instance.onchange === "function") {
          instance.onchange(value);
        }
      }
    }
    var timer = setInterval(checkHandler, delay);
    window.addEventListener("resize", checkHandler);

    var freed;

    function free() {
      if (freed) {
        return;
      }
      freed = true;
      window.removeEventListener("resize", checkHandler);
      clearInterval(timer);
    }
    instance.free = free;
    return instance;
  }
  exports.create = create;
  if (typeof define === "function") {
    if (define.amd || define.cmd) {
      define(function() {
        return exports;
      });
    }
  } else if (typeof module !== "undefined" && module.exports) {
    module.exports = exports;
  } else {
    window[exportName] = exports;
  }
})("jdetects");

jdetects.create(function(status) {
  alert(status);
});




0 个答案:

没有答案