Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation JavaScript & XML & NetScape

    I am trying to develop an App that will rotate Flash Movies without a postback. The Flash parameters are stored in a XML file and after loading the XML file I go through the nodes and build the string. I did not include the tags in the XML file (i.e. "<", ">" etc) because I thought it would be easy to just include them when I build the string in js. I AM NOT GOOD WITH JavaScript! (it would be easier to do this in .Net but I need the rotation to occur without postback) However after this script is debugged and working in IE, NN, FF etc. This will become apart of a .Net code behind file for a user control. Loading the xmlDoc works on IE, NN, FF etc. The problem is the function where I build the string:

    The Script:

    function createflsMovie()
    {
    var x = xmlDoc.getElementsByTagName('Ad');
    var flsStr = ' ';
    flsStr += '<' + x[0].childNodes[0].firstChild.nodeValue + x[0].childNodes[1].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[2].firstChild.nodeValue + x[0].childNodes[3].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[4].firstChild.nodeValue + x[0].childNodes[5].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[6].firstChild.nodeValue + x[0].childNodes[7].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[8].firstChild.nodeValue + x[0].childNodes[9].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[10].firstChild.nodeValue + x[0].childNodes[11].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[12].firstChild.nodeValue + x[0].childNodes[13].firstChild.nodeValue + ' ';
    flsStr += '> \n';
    flsStr += '<' + x[0].childNodes[14].firstChild.nodeValue + x[0].childNodes[15].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[16].firstChild.nodeValue + x[0].childNodes[17].firstChild.nodeValue + ' ';
    flsStr += '/' + '> \n';
    flsStr += '<' + x[0].childNodes[18].firstChild.nodeValue + x[0].childNodes[19].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[20].firstChild.nodeValue + x[0].childNodes[21].firstChild.nodeValue + ' ';
    flsStr += '/' + '>';
    flsStr += '<' + x[0].childNodes[22].firstChild.nodeValue + x[0].childNodes[23].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[24].firstChild.nodeValue + x[0].childNodes[25].firstChild.nodeValue + ' ';
    flsStr += '>';
    flsStr += '<' + x[0].childNodes[26].firstChild.nodeValue + x[0].childNodes[27].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[28].firstChild.nodeValue + x[0].childNodes[29].firstChild.nodeValue + ' ';
    flsStr += '> \n';
    flsStr += '<' + x[0].childNodes[30].firstChild.nodeValue + x[0].childNodes[31].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[32].firstChild.nodeValue + x[0].childNodes[33].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[34].firstChild.nodeValue + x[0].childNodes[35].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[36].firstChild.nodeValue + x[0].childNodes[37].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[38].firstChild.nodeValue + x[0].childNodes[39].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[40].firstChild.nodeValue + x[0].childNodes[41].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[42].firstChild.nodeValue + x[0].childNodes[43].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[44].firstChild.nodeValue + x[0].childNodes[45].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[46].firstChild.nodeValue + x[0].childNodes[47].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[48].firstChild.nodeValue + x[0].childNodes[49].firstChild.nodeValue + ' ';
    flsStr += x[0].childNodes[50].firstChild.nodeValue + x[0].childNodes[51].firstChild.nodeValue + ' ';
    flsStr += '>' + '<' + '/' + 'EMBED>' + '<' + '/' + 'Object>'

    This works fine in IE (the movie plays in the browser) but I get nothing in NN, FF. (no exceptions or nothing)

    So I started to break the script down and noticed some things that are different:
    ex)
    In IE the first available Node would be [0]
    In NN it is [1].

    So I tried this in the loadXML();

    var c = 0
    function importXML()
    {
    if (document.implementation && document.implementation.createDocument)
    {
    xmlDoc = document.implementation.createDocument("", "", null);
    xmlDoc.onload = createTable;
    c++;
    }
    else if (window.ActiveXObject)
    {
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.onreadystatechange = function () {if (xmlDoc.readyState == 4) createTable()};
    }
    else
    {
    alert('Your browser can\'t handle this script');
    return;
    }
    xmlDoc.load("../ctrlTemp/xml/intAd/intFlsAdSysblk.xml");
    }

    Now the variable c would keep my node count and I figured that I would increase the value after each line.

    ex)
    flsStr += '<' + x[0].childNodes[c].firstChild.nodeValue;
    c++;
    flsStr += x[0].childNodes[c].firstChild.nodeValue + ' ';
    c++;

    etc.
    This also worked for IE and it would work for NN if I had only one line but for some reason the concactenations are not liked well by NN, also when I use c++ more that once NN does not like it either. It also seems that NN does not like the '<' + ... either. Can some one please enlighten me as to how to get this script NN friendly?

    Oh the output is like so:

    document.getElementById('flsAd').innerHTML = (flsStr);
    }



    </SCRIPT>
    </head>

    <body onLoad="importXML()">
    <form runat="server">

    <Div ID="flsAd"></Div>
    </form>
    </body>
    </html>

    Which also works!

    Please Help!!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    So I started to break the script down and noticed some things that are different:
    ex)
    In IE the first available Node would be [0]
    In NN it is [1].
    Not exactly. Moz considers the gaps as possible textNodes, IE don't (at least not the first gap).

    So that either you build a function which will removes the gaps or you use nodeType attribute to check whether a childNode is a textNode or not.

    On the other hand, you must fill an empty tagged element with something if you want to use firstChild.nodeValue method. For instance use a nbsp

    <div id="myid">&nbsp;</div>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •