0

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?

2
  • 5
    May I ask what you're trying to accomplish here? Commented 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. Commented Mar 27, 2014 at 21:48

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

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.
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..
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.