复杂的JavaScript代码,我可以删除它吗?或者它的作用
Complex javascript code, can I just delete it? or what it does?
在我的网站 www.theprinterdepo.com 中,您可以查看页面源代码,我有一个代码,我的seo咨询建议我移动到外部文件。
它是一个建立在洋红色之上的电子商务网站。 它是一个免费的开源工具,所以我没有开发它,我只是安装了它。
我需要知道代码的作用。
window.HDUSeed='c7025284683262a8eb81056c48968d74';
window.HDUSeedIntId = setInterval(function(){
if (document.observe) {
document.observe('dom:loaded', function(){
for (var i = 0; i < document.forms.length; i++) {
if (document.forms[i].getAttribute('action') && document.forms[i].getAttribute('action').match('contacts/index/post')) {
var el = document.createElement('input');
el.type = ('hidden');
el.name = 'hdu_seed';
el.value = window.HDUSeed;
document.forms[i].appendChild(el);
}
}
});
clearInterval(window.HDUSeedIntId)
}
}, 100);
简介
此脚本每隔 100 毫秒左右调用一次函数(因为它不能保证),以尝试验证 DOM 的加载状态以在其上添加挂钩。
如果加载,它会处理页面中存在的所有表单,寻找具有"action"属性的表单(通常将其提交到某个地方,此处contacts/index/post
)。
对于找到的所有此类表单,它添加了一个新的包含"seed"值的隐藏输入元素,但是如果不了解有关代码库的更多信息,我们就无法告诉您它的用途。
详细的代码审查
// seed value, purpose unknown
window.HDUSeed='c7025284683262a8eb81056c48968d74';
// invoke this function every 100ms
// see: https://developer.mozilla.org/en/DOM/window.setInterval
window.HDUSeedIntId = setInterval(function(){
// checks if document.observe method exists (added by the Prototype
// JavaScript library, so we use this here to check its presence or
// that it's been already loaded)
if (document.observe) {
// hook on load status (when the page's DOM has finished loading)
// see: http://www.prototypejs.org/api/document/observe
document.observe('dom:loaded', function(){
// process all forms contained within the page's context
// see: https://developer.mozilla.org/en/DOM/document.forms
for (var i = 0; i < document.forms.length; i++) {
// only act on forms with the 'contacts/index/post/' action attribute
// see: https://developer.mozilla.org/en/DOM/document.forms
// and: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/match
if (document.forms[i].getAttribute('action') &&
document.forms[i].getAttribute('action').match('contacts/index/post')) {
// create an element...
// see: https://developer.mozilla.org/en/DOM/document.createElement
var el = document.createElement('input');
el.type = ('hidden'); // ... that is hidden
el.name = 'hdu_seed'; // w/ name 'hdu_seed'
el.value = window.HDUSeed; // and the seed value
document.forms[i].appendChild(el); // and add it to the end of the form
}
}
});
// Remove the interval to not call this stub again,
// as you've done what you want.
// To do this, you call clearInterval with the ID of the
// interval callback you created earlier.
// see: https://developer.mozilla.org/en/DOM/window.clearInterval
clearInterval(window.HDUSeedIntId)
}
}, 100); // 100ms
外部事物的某种分类。我的意思是像Google Analytics这样的服务。请记住,您是否为您的网站使用任何第三方服务。如果没有,我建议您删除它,看看会发生什么。如果它造成麻烦或其他事情,只需将代码恢复到文档中即可。
代码查找其操作为联系人/索引/帖子的表单,并尝试添加一个名为"hdu_seed"的隐藏字段。它看起来像一种反垃圾邮件措施,可能服务器希望收到它,如果它不存在,则忽略它。这样,不使用javascript的机器人将不会包含此字段,并且表单可能会失败。
编辑:它实际上一点也不复杂。
不知道setInterval
、clearInterval
和observe
函数在这里做了什么,这是逻辑的粗略概述
使用函数和整数100
调用setInterval
该函数检查是否已在此document
中加载observe
函数如果有,则它使用 dom:loaded
参数和函数调用 observe
函数并调用 clearInterval
函数,否则它不执行任何操作
内部函数循环访问文档中的每个form
。循环检查表单中的 action
属性。如果它存在并包含字符串contacts/index/post
则创建一个隐藏的input
元素,其name
为 hdu_seed
,value
为 window.HDUSeed
然后,它将此元素追加到form
。
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JQuery是否有一个“;移动“;作用或者有没有一种更紧凑的方法来做到这一点
- 如何在使用ng repeat时停止传播(或者如何更好地隔离作用域)
- 复杂的JavaScript代码,我可以删除它吗?或者它的作用
- 匿名函数在 Javascript 中不起作用?(或者也许我只是没有得到匿名函数)
- Concat 对象不起作用,或者我需要将值转换为正确的格式
- angular会将我的对象推到作用域之外,或者将对象与我的提供程序合并
- ruby中的作用域是否被认为像javascript一样具有功能,或者块作用域
- jQuery'或者'循环通过所需的输入元素时不起作用
- jQuery AJAX问题?或者JS OOP作用域问题
- 在文档内声明局部变量,或者在不同作用域的函数内声明局部变量
- 如何程序设置Javascript getter/setter ?(或者实际上是闭包作用域)
- 为CommonJS模块使用作用域函数的常见做法,或者不必要的
- 或者比较不起作用
- .innerHTML不起作用,或者我用错了