1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

JavaScript error, please help!

Discussion in 'Web Design & Development' started by rrrperson, Jul 29, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. rrrperson

    rrrperson Thread Starter

    Joined:
    Apr 27, 2006
    Messages:
    35
    Hi all. I'm working on a JS Browser and OS detection script. Every time I try to view/execute it, I get this error message:

    Line: 48
    Char: 1
    Error: Syntax error
    Code: 800A03EA
    Source: Microsoft JScript compilation error

    Line 48 reads as follows:
    Code:
    else if (ua.match("Opera")!=null){
    I have attached the .js file (b-det.txt, renamed for upload) for the convenience of anyone helping me.

    Thanks in advance.
     

    Attached Files:

  2. Shadow2531

    Shadow2531

    Joined:
    Apr 30, 2001
    Messages:
    2,636
    Look at the condition before that opera one.

    You can do:

    if, else if, else if, else if, else if, else

    , but you cannot do:

    if, else if, else if, else, else if, else

    Also, to detect opera, you can just use:

    Code:
    if ( window.opera ) {
        ua = "Opera";
        ver = window.opera.version();
    }
    
    ( For ancient versions of Opera you'll need to parse the ua string )

    Also, Opera ua strings, in addition to "Opera", can contain "MSIE", or "Mozilla" etc. That means, if you want to check for IE, you have to check the userAgent for "MSIE", but also check that it doesn't contain "Opera".
     
  3. rrrperson

    rrrperson Thread Starter

    Joined:
    Apr 27, 2006
    Messages:
    35
    You're right, shadow! There was a missing } at the end of the MSIE if...else. If you hadn't of told me to try looking before the Opera line, I never would have found it.

    I've done some heavy editing to it, and it finally works perfectly. I also moved the MSIE detection block to almost the last, so that Opera's "Identify as IE" option gets screened out before it gets to the MSIE block. I also fixed the getOS() function. It used to identify every windows version as Vista. I couldn't figure out why, so I tried replacing the switch case with an if...else, and it worked.

    Also, if anyone wants the final script, just ask.
     
  4. redivivus

    redivivus

    Joined:
    Mar 30, 2006
    Messages:
    1,458
    You know for next time... those error things are never accurate to the exact line / character! ;)

    Whats the script for?
     
  5. rrrperson

    rrrperson Thread Starter

    Joined:
    Apr 27, 2006
    Messages:
    35
    The script is to detect the browser, browser version, and operating system of the user.

    Also, the script error messages are too vague, maybe someone could point me to a good free script debugger? I tried Venkman, but couldn't get it to do anything. And also, you see, I use Firefox 1.5.0.5, and due to a bug, Venkman can only be run once on FF 1.5. Also, the Microsoft Script debugger refuses to install on my machine.

    Also, as stated in my last post, the final, working script is available upon request.
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/487614

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice