Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Disable a script?

    Is there a way to disable a SINGLE script on the page, something that a user can click and it disables only the script choosen?

    Thanks,
    Latchy

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Can you alter the script? If so, it's easy:

    Code:
    function existingFunctionOfSomeKind( possible, arguments )
    {
        if ( document.getElementById("zapMe").checked ) return;
        ... rest of code the same ...
    }
    And then simply add:
    Code:
    <label> 
        <input type=checkbox id="zapMe">
         Turn off irritating function
    </label>
    Or did you mean you wanted to disable an entire <script ...></script> block?

  • #3
    Regular Coder
    Join Date
    Jun 2008
    Posts
    102
    Thanks
    6
    Thanked 9 Times in 9 Posts
    if you want to remove a script block, i guess for dynamic unloading of objects..?? your best bet would be to just remove the object with the following...
    Code:
    function onclick()
    {
        //remove object from javascript memory space completely
        delete lameObject;
    }

    But to answer your question and remove script chunks, use this...
    Code:
    <script id="scriptToUnload" src="script/src.js" type="text/javascript" ></script>
    
    document.getElementsByTagName("head")[0].removeChild(document.getElementById("scriptToUnload"));
    That would remove the script tag from the document.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •