/    Sign up×
Community /Pin to ProfileBookmark

Javascript error only for limited users

I have a javascript error that is driving me nuts. I maintain a web site that has up to 1500 vists a day. Less than a handful of users have reported a failure of javascript elements in the pages. A few of those users have been helpful in giving me some specifics re the errors they are receiving. This is what I have found:

  • 1. My javascript is valid – using syntax checker such as lint detects no errors.

  • 2. It works for large majority of users – maybe 99% or more, on a variety of browsers, versions and O/S. I can’t recreate the problem (checked on W2k, XP, Linux, Mac, IE6, IE7, Opera, Konqueror, Ffox1.5, Ffox2 etc.)

  • 3. For those that have errors, some of the javascript works, some doesn’t (this rules out the disabling of javascript in the browser)

  • 4. The only common attribute of the users with errors are latest browsers (IE7, Ffox2) on XP. This should be a clue, but still can’t work it out. I have the same set-up available, but all is OK for me.

  • 5. I created sample pages for the users to test. I put an error alert in the header, which throws up “Object Expected” errors for them. That of course is javascript, and it proves that javascript does work for them (sometimes)!

  • 6. What fails to work in all situations for these specific users is when I put the a <script> entry in the header pointing to source elsewhere:
  • eg: <script type=”text/javascript” src=”jscript/xxxxx.js”></script>
    then in the body of the html I have:
    <script type=”text/javascript”>
    <!–
    bldHdg()
    // –>
    </script>

    (BTW, I have included/excluded language=”javascript” for no effect)
    7. In my samples I have inconsistent success with the following approach in the HTML:

    <script type=”text/javascript” src=”jscript/yyyyy.js”></script>

  • 8. Also in my samples I have inconsistent success with the following approach in the HTML:
  • <script type=”text/javascript”>
    var graphic2 = ‘images/conf_2008w/logo_120.jpg’;
    document.writeln(‘<img src=”‘ + graphic2 + ‘” alt=”filler” /> n’);
    </script>

    I stress that it may only be 1% or even less (based on feed-back). My thoughts are something environmental on the users PCs. My understanding of the “Object Expected” error is that it can’t find something it needs. Why does such a small minority not find the source, or execute selected javascript items?

    If I could recreate the problem, I reckon I could solve it. But relying on a non-technical remote third-party for feed-back is not productive.

    Any feed-back / suggestions appreciated.

    All my analysis tells me

    to post a comment
    JavaScript

    12 Comments(s)

    Copy linkTweet thisAlerts:
    @mrhooAug 01.2007 — The 'n' in your writeln call will be appended literally in the html-

    and it is unneeded, writeln adds a new line after its input automatically.

    But that won't throw an error.

    Most people do not report errors they encounter on websites- they navigate away, and mostly do not return.

    If you have a 'handful' of error reports, I'd assume there are more, and maybe many more visitors affected.

    It is most helpful to test your web pages from a variety of machines with different platforms and connections- use your friends, or internet cafes, even public libraries, if you have only one machine.
    Copy linkTweet thisAlerts:
    @bodauthorAug 01.2007 — I have access to multiple machines at home and away from home (work , family, friends). As indicated I have covered a wide range of those combinations but still not able to re-produce the problem. I only have a few users with these errors who have come forward, from which I now have some screenprints from them as evidence of such problems.

    However I'll try removing the "/n" from writeln. As you point out, it should still not generate an error. I'm hoping that some-one else has had a similar experience and able to offer some advice.
    Copy linkTweet thisAlerts:
    @DokAug 01.2007 — One common cuase of inconsistent errors is trying to execute javacsript code before the [I]entire[/I] page is loaded. You might end up in a situation where you are referencing an element which have not yet been created and this will give you errors like "Object expected" or "whatever is undefined".

    In my opinion you sould always start execution of javascript code with the onload event on the body tag.
    Copy linkTweet thisAlerts:
    @bodauthorAug 01.2007 — Dok,

    That makes sense - not all code has been loaded.

    Is there a guaranteed way to ensure all code is pre-loaded? Should all code be paced in header (preferably as references to source files as I use the javascript to share common page components) and all execution as an on-load event? I have some javascript that is placed inside the body and it works OK (even for the users that experience these errors)
    Copy linkTweet thisAlerts:
    @DokAug 01.2007 — Is there a guaranteed way to ensure all code is pre-loaded?[/QUOTE]Yes. Do something like this
    [code=html]<html>
    <head>
    <script type="text/javascript">
    function init() {
    // Start your code here
    // All files, scripts, pictures etc. are now loaded
    }
    </script>
    </head>
    <body onload="init();">
    </body>
    </html>[/code]
    Copy linkTweet thisAlerts:
    @bodauthorAug 02.2007 — Unfortunately I do have such a scenario (source in header and on_load event) and that does not work for these users. In my tests for them I have both referenced a source file in the header, and also pasted the javascript code inline in the header, and neither works.

    What would be the cause of some configurations trying to execute before all code is loaded? Is there some setting in the browsers (I can't find anything).

    Two other pieces of information - don't believe it is relevant, but just in case. The pages use the ".shtml" suffix as I also use SSI. And the pages are built to XHTML 1.0 Transitional standard.
    Copy linkTweet thisAlerts:
    @DokAug 02.2007 — Unfortunately I do have such a scenario[/QUOTE]What scenario?

    The onload event will not fire untill the entire page has been loaded [I]including[/I] external javascript files
    Copy linkTweet thisAlerts:
    @Arty_EffemAug 02.2007 — I maintain a web site that has up to 1500 vists a day.[/QUOTE]Is it confidential or can anyone view it?
    Copy linkTweet thisAlerts:
    @bodauthorAug 02.2007 — The site is not secret - I was just trying to tackle the problem from a theoretical POV.

    The current main page is:

    www.alpaca.asn.au

    I have constructed some samples for the few users who have reported the problems, the latest being

    www.alpaca.asn.au/sample4.shtml

    I don't pretend to be the best javascript coder, but I can't replicate the issues.
    Copy linkTweet thisAlerts:
    @DokAug 02.2007 — @ bod: You didn't answer my question.
    Copy linkTweet thisAlerts:
    @mjdamatoAug 02.2007 — Your test page was fine, but I recieved the following errors on a couple pages on your site:

    Page: http://www.alpaca.asn.au/sitemap.shtml

    Line: 241

    Error: 'document.adRHS' is null or not an object

    Page: http://www.alpaca.asn.au/AAA/contact/regsec.shtml

    Line: 151

    Error: Syntax Error

    Line: 268

    Error: 'document.nextHSAd' is null or not an object

    However, these are occuring on included code, so I didn't want to have to take the time right now to find the real lie numbers. Hope that info helps.
    Copy linkTweet thisAlerts:
    @bodauthorAug 02.2007 — to Dok,

    The scenario I was referring to was that I do have a javascript source file specified in the the HTML header, and the onload event calling the function.

    From your other response, and the last one from user "mjdamato" has given me some leads. The missing "document.nextHSAd" is actually specified in another javascript file. Hence if the two are not fully loaded, then such an error will occur. My code is not fully self-contained - ie. can stand-alone.

    Also I am referencing CSS items, where the CCS source file is referenced in the header. Could this also not be fully loaded before the page is trying to execute the script?
    ×

    Success!

    Help @bod spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.21,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...