I have a javascript working great on Mozilla but not on Safari or Chrome

Discussion in 'Web Design and Development' started by BG29, Jun 2, 2013.

  1. macrumors newbie

    Jun 2, 2013
    Do you have any suggestion?

    I modified some codes from http://www.w3schools.com/xml/ and get something fine to parse XML database.
    Well ... at least it is fine with Mozilla on a PC... but it does not work either with Safari or Chrome on a Mac (or PC) ... any suggestion is most welcome!
    the page is on:
    and the related files are on:

    Thanks in advance!
  2. SrWebDeveloper, Jun 3, 2013
    Last edited: Jun 3, 2013

    macrumors 68000


    Dec 7, 2007
    Alexandria, VA, USA
    So I typed in "7" and pressed Enter and saw some author/year/title info from your XML DB display above the buttons, but not on Chrome. Console inspection on Chrome reveals:

    These issues do not appear to be browser specific, simply that some browsers parse JS very strictly which means you need to adjust your code (in a few places) so variables and objects are properly defined or referenced to work in a strict environment for cross browser compatibility. See listing of errors above to help you know where to look and what to fix.

    Example: in display.js line 12 the "x" you have:

    for (var i=1;i<x.length;i++)
    But "x" is not defined locally (in display.js) or globally, apparently, so some browser might return 0 for x.length while others properly complain about it. Follow best practices and always define var's properly and less headaches and better cross platform compatibility, plus code is easier to follow when debugging. I didn't spend much time debugging, so this is informal advice.

    Use Crome and its built in inspection tools and use the console tab for checking JS errors. Add on the Web Developer extension and you can even local edit! FYI.

  3. thread starter macrumors newbie

    Jun 2, 2013
    "I am not an IT person"

    THANKS ...
    I get your points (there are errors in my code, I should use this Chrome facility, ...).
    I should try to learn more on javascript and possibly to better understand what I "wrote" (="copied and pasted") ...
    but I am not an IT person (I am a paleontologist ...).

    Therefore --in the mean time-- any support is most welcome.

    Thanks again (and in advance)
  4. macrumors 65816

    Apr 17, 2012
    Destin, FL
    Haha! Maybe I just caught this with the correct amount of port in me, but this cracked me up ( in a fantastic way ).

    I love this part:
    I'm making a T-Shirt and probably a coffee mug out of that!

    Here's what my befuddled (thank you spell checker) mind thinks:
    When my dog digs up a huge dino bone, I'm going to head over to your forum and ask questions and when given reasonable answers respond with: Yeah, yeah, i get it, I shouldn't be using a chainsaw to chop this thing up into more mangeable pieces, but I'm an IT guy not a palentologist ( think I'd get on a T-Shirt? ).

    Okay... to actually help you we would need to see the source code and find out why you didn't assign a default value to x. And show you where and how to do that.

    Could you post your source? I'll be sure to post pictures of the dino bone my dog digs up.

    PS Please forgive me, upon rereading that it was meant to be funny but seemed mean, I promise I mean no snide or ill in your direction. I just truly thought your response was funny.
  5. thread starter macrumors newbie

    Jun 2, 2013

    you will find the code on the URL links of my first message (with .js files set apart) ... the "new" URL of the title gets the JS in the HTML code!

    It is not a problem making humour with "my quote".

    Apologies for my poor English too ...

    If you are clever (I assume you are) and a little curious
    you possibly removed the final "display.js" to get access to the folder at
    (if you are even more curious you would have removed "test/" and found that I am editing an Open Access scientific journal)

    You will find that I am using a set of script called Tipue, which is very effective to search in a flat JS database.

    And you will also find the browse related items ... the ones that do not work!
    I copied most of the pieces of code from SEVERAL scripts available at
    and tried to assemble them in the "good" way
    it worked with Firefox, not with Safari or Chrome

    I first thought it was a Mac issue (because I do not have Chrome and Safari on my PC) as I checked whether it was working on an Ipad and then on my Mac (I do not have Firefox on my Mac, nor Chrome)

    So may be I am not in the good forum to help solve this problem.

    Let us go back to what I ideally wished:
    1) getting a search engine to browse a database (I get this with Tipue but I had to rewrite my original XML database and convert it into a flat JS database)
    2) getting a tool to screen each entry of my XML data, with in addition the possibility to go to a discrete entry, to go to entries 1, 5 and 20 steps below or above
    this is this part which I did not manage to build correctly ...

    what I am doing is like cooking with a cookbook in Spanish (that I understand at 80%) and eventually without having the good ingredients ...

    If this issue can be fixed it might be a very practical tool for small database (the one we use here get some 7600 entries)


    Thanks for your appreciated help


    I should mention that I checked the "JS console" on Chrome as suggested by SrWebDeveloper but AGAIN the red quotes looked like Chinese too me :D
  6. macrumors 65816

    Apr 17, 2012
    Destin, FL
    What? Your english is better than english writers that make millions by writing english text books, so don't worry about that at all.

    I did not browse your code, most of us have limited time, and cannot dive too deeply in another's code, that's why I asked you to copy paste the relative parts. For example, right now I have about three minutes until my compile is done and then back to work. I really don't have the time to download and search your hard work, as I'm in the process of fixing mine ( actually someone else's code, but that's a different story ).
  7. macrumors 68000


    Dec 7, 2007
    Alexandria, VA, USA
    I laughed out loud, too, when I saw "but I am not an IT person (I am a paleontologist ...)" and here's my $1.99 for a T-shirt. :p

    I'm in agreement with 960design, BG29. Most of us cannot take the time to resolve all the code fixes which in this case are not merely syntax errors but changes involving missing pieces since you copy/pasted and merged code from different sources. In this unique kind of situation we do what I did in my first reply, offer suggestions and point out what failed and notably how to more quickly debug those issues using the common tools we in IT use all the time.

    You might find someone here willing to dive into your mixed/merged code and create a better script from it that 1) resolves the browser compatibility issues and 2) performs the task as you described in your last reply. Or, as you said:

    .... or hire a professional.
  8. thread starter macrumors newbie

    Jun 2, 2013

    well actually I had to set the code to generated a discrete id for each div
    I replaced
      document.write("<div id='showCD' onclick='displayCDInfo(" + i + ")'></div>");
    document.write("<div id='showCD(" + i + ")' onclick='displayCDInfo(" + i + ")'></div>");
    it works with Chrome too


    anyway if you have a better ("smarter") way to get the same results I would welcome it (and acknowledge it in the forthcoming publication).


Share This Page