jssdk 덮어쓰기 방지

2895 단어

덮어쓰기 방지
var isFromTuia = (function () {
    var tuiaDomains = ['tuisnake', 'localhost']

    function GetUrlDomain(url) {
      var arrUrl = url.split("//");
      var start = arrUrl[1].indexOf("/");
      var relUrl = arrUrl[1].substring(0, start); //stop , start 
      return relUrl;
    }

    var es = document.getElementsByTagName('script');
    var iScript = es[es.length - 1]
    if (iScript && iScript.src) {
      var iDomain = GetUrlDomain(iScript.src);

      for (var i = 0; i < tuiaDomains.length; i++) {
        if (iDomain.indexOf(tuiaDomains[i]) != -1) {
          return true;
        } 
      }
    }

    return false;
  })();

  function defineTaWin(key, value, isFreeze) {
    if (Object.defineProperty && isFreeze) {
      Object.defineProperty(window, key, {
        writable: false,
        value: value
      });
    } else {
      window[key] = value;
    }
  }

  defineTaWin('countLog', countLog, isFromTuia);

 https://inuanfeng.github.io/test/referend.html

좋은 웹페이지 즐겨찾기