Is it possible to remove/disable internal JavaScript on a page after 'X' minutes so that it does not work at all after 'X' minutes of time?
-
5May I ask what you're trying to accomplish here?Benjamin Gruenbaum– Benjamin Gruenbaum2014-03-27 21:38:40 +00:00Commented Mar 27, 2014 at 21:38
-
Programmatically, or do you want to disable just for your browser? You can go into your browser settings and turn javascript off. For timing, you can use a stopwatch or good ole' one miss-i-ssi-pi, two miss-i-ssi-pi. But with JavaScript itself, you do not have the ability to disable.jOshT– jOshT2014-03-27 21:48:47 +00:00Commented Mar 27, 2014 at 21:48
Add a comment
|
1 Answer
Try like below,
<script type="text/javascript" id="hideAfter">
// your code here...
// it will removes the script tag after 10 sec...
setTimeout(function () {
var ele = document.getElementById("hideAfter");
ele.parentNode.removeChild(ele);
}, 10000);
</script>
3 Comments
t.niese
Removing a
script node of an already parsed and evaluated script will just remove the node from the DOM. The code that was defined there will still exist.Soundar
For this case, we need to stop the functionality inside the script block before going to remove.. otherwise the operations are performed in the memory.. But i don't know exactly this is the efficient way.. but this is one of the possible way..
t.niese
Your answer indicates that removing the
script node would have an effect to the code that was loaded by that node - that it would stop running, disappear from memory or that it would not be possible to call it anymore - but this is not the case.