SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,657
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    anyway to toggle javascript on/off from on the website - verses from the browser?

    Hello,

    Is there anyway to toggle javascript on and off from a button on the actual website - verses from the browser? I have a js demo, and I would like to give the user the ability to toggle js on and of with a button within the demo. Possible or no? Thanks!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Of course not. That would give a website too much control over the person's browser. The best way to toggle it off via your webpage is to simply not use it.

    Within your demo, with JS on, the function runAllMyDemoJS() runs. It also has the capability of stopping whatever it's doing, upon the event of the user clicking something, which destroys event listeners, stops animations, etc.

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,657
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    OK thanks. However, I don't quite follow how to implement what your saying. Anyway you can break that down for me?

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's simply a case of undoing what your javascript does. So if some extra HTML elements are added when the page loads, clicking the button would remove them. If some nice effects are added when links are moused over, those event listeners are removed. If clicking form fields shows some helpful text nearby, those event listeners are removed as well.

    Since most javascript interaction with the user is driven by events, it is a case of writing good code where it is possible to keep track of event listeners you're applying and also being able to remove them. You would most likely need an addEvent and a removeEvent function in order to incorporate addEventListener, removeEventListener, attachEvent, detachEvent and, if you wish, the simple canonical ones (onclick, onmouseover, onscroll, etc.) though browsers are modern enough nowadays to not need them.

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,657
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Mmmm? I guess I'm slow? Here let me show you the page that I would like to add, or take away rather, the function.

    http://www.visibilityinherit.com/cod...ns-example.php

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    OK, now you need a function called unmatchColumns that undoes what matchColumns did. This will largely involve removing the style attributes (or perhaps just setting style.height = '') for your columns, since that is what matchColumns does.

    By the way, there are ways to achieve what you're doing without JavaScript, i.e. making columns the same height regardless of content, with CSS only. Look at the 3 column sticky thread at the top of the CSS forum.

    Off Topic:

    Also by the way, I don't like the way your site changes my mouse cursor.


Bookmarks

Posting Permissions

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