View Full Version : Disable Javascript for selected browsers

11-30-2006, 03:18 PM
Does anyone have a script to disable a browser running javascript altogether,

I don't know much about code, but I need something like:

If Mozilla....
then disable Javascript.

Is it possible, please say it is.

11-30-2006, 03:42 PM
Er.... no.

It's contradictory to "disable" something with the same language it's in.

Here's your code*--

if (UserAgent != "Firefox" || UserAgent!=...) { dostuff(); }

*This is wrong.
UserAgent is not the correct constant to use for the user's browser, but it is available... just look that up. And I don't think Firefox is returned for FF, but something is.... look that up too.

Now, you could have a white list ALLOWING certain browsers (==, &&) or a black list DISALLOWING certain browsers (!=, ||), with the main difference being what happens to browsers not account for.
For example, if you disallow FF, then both IE and Opera are ok. But if you allow IE, then neither FF nor Opera will sneak by.

The other, smarter in most cases, way of doing this is checking if a function/feature is available before it's use, so that you have the script there, but you do not execute anything that is going to cause problems.

Also, if you are asking whether you can change that setting in their browser, then, no, the choice of enabling/disabling javascript is that of the user, and their preferences/settings cannot be altered from a webpage.

12-01-2006, 02:51 PM
No, it isn't, although if you tell us why you're attempting to do this, perhaps we can offer an alternative solution.

12-01-2006, 03:48 PM
The reason is because my javascript scrollbar at the top of my page http://www.cdcza.co.za breakes my images when I view it in Mozilla FF, If i disable the javascript (scrollbar) it looks fine. So I want IE to run the script (because it looks fine in IE) and Mozilla and NS to ignore the script.

12-01-2006, 03:54 PM
Try conditional comments:
<!--[if IE]>
Script here.