Results 1 to 5 of 5

Thread: Disable Javascript for selected browsers

  1. #1
    Join Date
    Nov 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Disable Javascript for selected browsers

    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.
    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, it isn't, although if you tell us why you're attempting to do this, perhaps we can offer an alternative solution.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Nov 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Try conditional comments:
    Code:
    <!--[if IE]>
    Script here.
    <![endif]-->
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •