View Full Version : Toggling Javascripts
[lhomme]
May 26th, 2002, 11:25
Is there a way to let users toggle a javascript on and off - with on being the default? Preferably, this toggling of the javascript would remain permanent unless toggled again by the user.
As always, thanks again.
Dusty
May 26th, 2002, 13:03
You mean from the page? No, that would defeat the purpose of being able to turn it off. If you mean from the browser, of course. In Mozilla, for example, Edit > Preferences > Advanced > Scripts & Windows uncheck "Enable JavaScript for:" "Navigator" and "Mail & Newsgroups".
If you just want to toggle the scripts on your own page, though, that could be done. You'd just have to build in some kind of switch in each of them that would check the value of some form element on the page then either continue with the script or stop running. It wouldn't really disabled JavaScript, but it would seem to.
There might be some security flaw you can exploit in IE 5.x that would let you really do it, but I doubt it would work on 6, though, and it certainly wouldn't work on anything else.
[lhomme]
May 26th, 2002, 15:33
Whoops - seems I wasn't being clear.
I have a (one) javascript on my page that I want users to be able to choose whether or not to leave on or turn off. I assume that since I want to the change to be permanent (until toggled on), that I would need to use cookies. Any ideas?
Dusty
May 26th, 2002, 15:54
You could use cookies, yes, or just pass the on/off value through the query string of all your links. The cookie would be easier, but the other way would work for people that disallow cookies.
<script language="JavaScript"><!--
if(!document.cookie.match("script=off")){
(script here)
}
//--></script>
<a href="#" onClick="document.cookie='script=on';">on</a>
<a href="#" onClick="document.cookie='script=off';">off</a>
[lhomme]
May 27th, 2002, 12:56
Didnt realize that it would be that simple. Thanks.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.