不安全的js写法

Posted on September 11, 2009 by Fdream

一种很常见的写法:

document.write('<scr'+'ipt src="http://a.com/b.js" type="text/javascript"></scr'+'ipt>');

直到被杀毒软件提示有恶意代码才发现这也是不安全的,汗……

那就只好改成这样了:

(function() {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.src = 'http://a.com.cn/b.js';
    document.getElementsByTagName('head')[0].appendChild(s);
})();

搜了一下,原来还有“邪恶”的eval,具体可以看这里:网马解密大讲堂——网马解密中级篇(Document.write篇)

分享 |
Categories:
Ajax Web
Tags:
,
Comments:
Leave a comment
Views:
3,635 Views

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>