最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Does removing a script element remove its functions from memory? - Stack Overflow

programmeradmin2浏览0评论
var scripts  = document.getElementsByTagName("script");
for (var i=scripts.length; i--; ){
   (scripts[i]).parentNode.removeChild(scripts[i]);
}

Someone asked me this question and my first thought was: no. However, when you remove the style elements, the page automatically updates, removing the styling. This could be because of how the browser hooks css - I think I recall that CSS updates on every event (mouse movement, clicks, type, etc).

I just wanted to confirm, that getting rid of the script tag, won't get rid of the function that was already created, since I'm not at a puter where I can test.

This also has got me thinking of good practice to help secure code against firebug[-like] users

var scripts  = document.getElementsByTagName("script");
for (var i=scripts.length; i--; ){
   (scripts[i]).parentNode.removeChild(scripts[i]);
}

Someone asked me this question and my first thought was: no. However, when you remove the style elements, the page automatically updates, removing the styling. This could be because of how the browser hooks css - I think I recall that CSS updates on every event (mouse movement, clicks, type, etc).

I just wanted to confirm, that getting rid of the script tag, won't get rid of the function that was already created, since I'm not at a puter where I can test.

This also has got me thinking of good practice to help secure code against firebug[-like] users

Share Improve this question asked Jan 31, 2012 at 16:05 vol7ronvol7ron 42.2k22 gold badges125 silver badges175 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Short answer, No.

Any script which got evaluated once by the engine will stay in memory for the rest of your session. Even by removing the entire script node where the code was contained doesn't change that fact.

发布评论

评论列表(0)

  1. 暂无评论