www.webdeveloper.com
Results 1 to 9 of 9

Thread: Enable/Disable JS

  1. #1
    Join Date
    Sep 2011
    Posts
    12

    Enable/Disable JS

    Hey guys, I've got this external javascript file ( http://epicurus-rsps.net/forum/jscripts/snowstorm.js ), yes, it's a snow plugin.

    So I want to make it toggleable, so a user can either toggle to have it on or off (due to it causing some lagg).

    Is there a way to enable/disable the use of a js file through the onClick function?

    Thanks in advanced.

  2. #2
    Join Date
    Dec 2012
    Posts
    54
    It looks like it has a method called
    Code:
    this.freeze();
    Not sure how you are implimenting it but it should be something like

    Code:
    <button onclick = "snowStorm().freeze()">
    You could even do something a little more intuitive on the lines of
    Code:
    <script>
      function ToggleSnowStorm(){
        if(!snowStorm().disabled)
          snowStorm().freeze();
        else
          snowStorm().resume();
    </script>
    ...........
    <button onclick = "ToggleSnowStorm()"/>
    Obviously the code may not be exact since I don't see your page but this should give you an idea of where to start.

    If you look into cookies you could probably use a cookie to see if the user prefers it toggled on or off if you expect to have return visitors.
    Last edited by Lesshardtoofind; 12-22-2012 at 05:09 AM.

  3. #3
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Actually, snowStorm is an object and not a function. So you should just write snowStorm instead of snowStorm().

  4. #4
    Join Date
    Dec 2012
    Posts
    54
    My apologies
    Code:
    <script>
      function ToggleSnowStorm(){
        if(!snowStorm.disabled)
          snowStorm.freeze();
        else
          snowStorm.resume();
    </script>
    ...........
    <button onclick = "ToggleSnowStorm()"/>

  5. #5
    Join Date
    Sep 2011
    Posts
    12
    Oh wow... thanks for the input Lesshardtoofind, but theres a flipping .toggle function in the .js D===

    Dog dangit!

  6. #6
    Join Date
    Dec 2012
    Posts
    54
    I figured there should be. Good luck!

  7. #7
    Join Date
    Nov 2010
    Posts
    1,036
    so why not use the toggle function?
    Code:
    <input type="button" value="toggle snow" onclick="snowStorm.toggleSnow();">

  8. #8
    Join Date
    Sep 2011
    Posts
    12
    Quote Originally Posted by xelawho View Post
    so why not use the toggle function?
    Code:
    <input type="button" value="toggle snow" onclick="snowStorm.toggleSnow();">
    Quote Originally Posted by Chompin View Post
    Oh wow... thanks for the input Lesshardtoofind, but theres a flipping .toggle function in the .js D===

    Dog dangit!
    I posted that like an hour ago.

  9. #9
    Join Date
    Nov 2010
    Posts
    1,036
    so you did. pardon my lackluster page refreshing habits

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles