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 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Getting firstChild.innerHTML properties to work with Netscape

    This is part of a script that I am working on...

    How do I get this to work with Netscape?? It works fine with Internet Explorer but, Netscape won't recognize any of the properties of firstChild.innerHTML?? How do I work around this?

    if (firstChild.innerHTML.charAt(firstChild.innerHTML.length-1)==" ")
    {
    firstChild.innerHTML=firstChild.innerHTML.slice(0,-2);
    }
    Basically, I'm just using this part of the script to trim off some extra whitespace.
    Last edited by theekid182; 01-06-2005 at 08:32 PM.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Gecko preserves whitespace nodes. In other words:

    Code:
    <element>
        <child>some text</child>
    </element>
    element.firstChild is a TextNode (the indentation), no the <child> element which you'll get in IE. You could use element.getElementsByTagName("*")[0] to generate identical results between the browsers, or use some intelligent filtering.

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I am trying to do is create a script that makes me appear to be logged in to my message boards 24/7 even if I'm really not. There is a person who spams my board using Mozilla with proxies. However, they never spam while I'm logged in. So that's why I'm working on this. This is what I have so far... The script works great in IE... just not in Netscape.

    PHP Code:
    <script type="text/javascript">
    <!--

    var 
    iFakes = [
    "admin"
    ];

    var 
    iCell document.getElementsByTagName("td");

    for(
    c=0;c<iCell.length;c++)
    {
       
    with(iCell[c])
       {
          if(
    vAlign=="top" && align=="left" && innerHTML.match(/d+sGuest[s]?,s((d+)sMember[s]?)/i))
          {
          
             if (
    navigator.appName=="Microsoft Internet Explorer"
             {
          
                if (
    firstChild.innerHTML.charAt(firstChild.innerHTML.length-1)==" ")
                {
                   
    firstChild.innerHTML=firstChild.innerHTML.slice(0,-2);
                }
                
                var 
    first=true;
                for(
    f=0;f<iFakes.length;f++)
                {
                   var 
    iLen iFakes.length Math.floor(RegExp.$2);
                   var 
    Len = (iLen == 1)? iLen " Member" iLen " Members";
                   
    firstChild.innerHTML innerHTML.replace(RegExp.$1,Len)
                   
                   if(
    iLen-iFakes.length==&& first==true)
                   {
                      
    firstChild.innerHTML += '<a href="index.cgi?action=viewprofile&username=' iFakes[f] + '">' iFakes[f] + '</a>';
                      
    first=false;
                   }
                   else
                   {
                      
    firstChild.innerHTML += ', <a href="index.cgi?action=viewprofile&username=' iFakes[f] + '">' iFakes[f] + '</a>';          
                   }
                }
                
             }
             
             
             else
             {
            
            
    // This part doesn't work
                // if (firstChild.innerHTML.charAt(firstChild.innerHTML.length-1)==" ")
                // {
                //   firstChild.innerHTML=firstChild.innerHTML.slice(0,-2);
                // }
                
                
    var first=true;
                for(
    f=0;f<iFakes.length;f++)
                {
                   var 
    iLen iFakes.length Math.floor(RegExp.$2);
                   var 
    Len = (iLen == 1)? iLen " Member" iLen " Members";


                   if(
    iLen-iFakes.length==&& first==true)
                   {
                      
    firstChild.innerHTML += '<a href="index.cgi?action=viewprofile&username=' iFakes[f] + '">' iFakes[f] + '</a>';
                      
    first=false;
                   }
                   else
                   {
                      
    firstChild.innerHTML += ', <a href="index.cgi?action=viewprofile&username=' iFakes[f] + '">' iFakes[f] + '</a>';          
                   }     

                }
                
    firstChild.innerHTML innerHTML.replace(RegExp.$1,Len)
             
             
             }
          }
       }
    }

    //-->
    </script> 
    It's just that one part that doesn't work.

    What it shows in Netscape is "realuser1, realuser2, realuser3 , fakeadmin1, fakeadmin2"

    I'm trying to get rid of that extra space before the comma and I can't figure it out.
    Last edited by theekid182; 01-06-2005 at 09:02 PM.

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Wouldn't it be easier just to edit the template?

  • #5
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jkd
    Wouldn't it be easier just to edit the template?
    I'm using proboards and they don't allow that... they just allow additional header and footer codes... That's why I have to do it this way. Is there a way to filter out the first instance of " , " and replace it with ", " or is there something else that I need to do? Or is there another way to remove the second last character from firstChild.innerHTML before I begin the loop (like what I did for IE).
    Last edited by theekid182; 01-06-2005 at 10:26 PM.

  • #6
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Not sure exactly what outcome you are looking for but this will work in IE and Gecko-based browsers:

    <script type="text/javascript">
    function fakeIt()
    {
    // get reference to node
    el = document.getElementById('firstChild').childNodes[0];
    // get reference to node value
    elValue = document.getElementById('firstChild').childNodes[0].nodeValue;

    //look for white space at end of text
    if((elValue.search(/[\s+]$/))>-1)
    {
    el.nodeValue = el.nodeValue.slice(0,-2);
    }
    }
    </script>
    </head>
    <body onLoad="fakeIt()">
    <div id="firstChild">
    Hello
    </div>
    Last edited by Puffin the Erb; 01-06-2005 at 10:57 PM.

  • #7
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is what that part of the HTML on my board looks like before the script is run.
    PHP Code:
    <table width="98%" cellpadding="3" align="center">
    <
    tr>
    <
    td valign="top" align="left"><font size="1">13 Guests1 Member<BR><A HREF="index.cgi?action=viewprofile&username=guy22">SomeGuy22</A>
    </
    font></td>
    </
    tr>
    </
    table
    Last edited by theekid182; 01-07-2005 at 12:45 AM.

  • #8
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the HTML and javascript together. Hopefully, this'll give you a better idea of the kind of result that I'm looking for...

    PHP Code:
    <!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -->
    <
    html>
    <
    head>

    <
    style type="text/css">
    <!--
    /* General layout */
    A:link        text-decorationnonecolorceeede; }
    A:visited     text-decorationnonecolorababbb; }
    A:hover       text-decorationunderline overlinecolorceeede; }
    BODY          font-familyTahoma;
                    
    font-size:12pxmargin-top0margin-left0margin-right0padding-top0padding-left0;
                    
    padding-right0; }
    TD            font-familyTahomacolorDDDDAAfont-size:11px}
    input         font-familyTahomafont-size9ptcolor000000; }
    textarea      font-familyTahomafont-size9ptcolor000000; }
    select        font-familyTahomafont-size7ptcolor000000; }

    .
    nav          font-size10pxtext-decorationnonecolorDDDDAA; }
    .
    nav:link     font-size10pxtext-decorationnonecolorceeede; }
    .
    nav:visited  font-size10pxtext-decorationnonecolorababbb; }
    .
    nav:hover    font-size10pxtext-decorationnonecolorceeedefont-weightboldtext-decorationunderline; }

    .
    windowbg     background-color203164font-size11pxfont-familyTahomacolorDDDDAA; }
    .
    windowbg2    background-color1F2369font-size11pxfont-familyTahomacolorDDDDAA; }
    .
    windowbg3    background-colorFFB903font-size11pxfont-familyTahomacolorDDDDAA; }

    .
    hr           color43478D;}
    .
    titlebg      background-color2D6F39colorDDDDAA; }
    .
    text1        font-stylenormalfont-weightboldfont-size12pxcolorDFD294; }
    .
    catbg        background-color53478DcolorDDDDAAfont-weightboldfont-size13px; }
    .
    bordercolor  background-color9DDFA9; }

    .
    quote        font-size10pxfont-familyTahomacolorDDDDAAbackground-color1F2369; }
    .
    code         font-size10pxfont-familyCourier New; colorDDDDAAbackground-color1F2369; }
    -->
    </
    style>
    <
    script language="JavaScript1.2" type="text/javascript">
    <!--
      if ((
    navigator.appVersion.substring(0,1) == "5" &&
    navigator.userAgent.indexOf('Gecko') != -1) ||
    navigator.userAgent.search(/Opera/) != -1) {
       
    document.write('<META HTTP-EQUIV="pragma" CONTENT="no-cache">');
      }
    // -->
    </script>
    </head>
    <body text="DDDDAA" bgcolor="43478D" link="ceeede" vlink="ababbb" alink="" background="http://img78.photobucket.com/albums/v298/theekid182/deep_sea4.jpg">

    <CENTER>
    <table width="92%" cellspacing="0" cellpadding="0" align="center"><!-- change celpadding from 3-->
      <tr>
        <td valign="TOP" width="100%">
          ...<BR>

    <table border=0 width="100%" cellspacing="0" cellpadding="0" bgcolor="9DDFA9" class="bordercolor">
    <tr>
    <td>
        <table cellpadding="4" cellspacing="1" border="0" width="100%">
        <tr>

        <td bgcolor="2D6F39" class="titlebg" align="center" colspan="2">
        <font class="text1" color="DDDDAA" size="2"><b>Info Center</b></font></td>
        </tr><tr>
        <td class="catbg" bgcolor="53478D" colspan="2"> <font size="2" class="cattext" color="DFD294"><b>Forum Statistics</b></font></td>
        </tr><tr>
        <td class="windowbg" bgcolor="203164" width="20" valign="middle" align="center"><IMG SRC="http://img78.photobucket.com/albums/v298/theekid182/info.gif" BORDER=0></td>
        <td class="windowbg2" bgcolor="1F2369" valign="top" align="center"><font size="1">

            <table width="98%" cellpadding="3" align="center">
            <tr>
            <td valign="top" align="left" width="60%"><font size="1">
            Total Topics: <B>1233</B> &nbsp; - &nbsp; Total Posts: <B>5273</B>
            <BR>Last Updated Topic: <B><A HREF="index.cgi?board=tech1&action=display&num=1104094027&start=0">Current Video Game Consoles</A> by <A HREF="index.cgi?action=viewprofile&username=Mp3170Counting"><B>stashkid</B></A> (<B>Today</B> at 3:13pm)</B><BR>View the <A href="index.cgi?action=recent">10 most recent posts</a> of this forum.
            </font></td>

            <td valign="top" align="left" width="40%"><font size="1">
            Total Members: <a href="index.cgi?action=mlall"><B>1107</B></a>
            <BR>Newest Member: <A HREF="index.cgi?action=viewprofile&username=lellolello4"><B>lellolello4</B></A><BR>Your Instant Messages: 
            <a href="index.cgi?action=im"><b>312</b></a> New: <a href="index.cgi?action=im"><B>0</B></a></font></td>
    </tr>
    </table>

    </font></td>
    </tr><tr>
    <td class="catbg" bgcolor="53478D" colspan="2"> <font size="2" class="cattext" color="DFD294"><b>Users Online</b></font></td>
    </tr><tr>
    <td class="windowbg" bgcolor="203164" width="20" valign="middle" align="center"><IMG SRC="http://img78.photobucket.com/albums/v298/theekid182/online.gif" BORDER=0></td>
    <td class="windowbg2" bgcolor="1F2369"><font size=1>
    <table width="98%" cellpadding="3" align="center">
    <tr>
    <td valign="top" align="left"><font size="1">9 Guests, 1 Member<BR>
    <a href="index.cgi?action=viewprofile&username=admin">Admin</a>
    </font></td>
    </tr>
    </table>

    </font></td>
    </tr>
    </table>
    </td>
    </tr>
    </table><BR>
        </td>
      </tr>
    </table>
    </CENTER>

    <script type="text/javascript">
    <!--

    var iFakes = [
    "admin2","admin3","admin4"
    ];

    rndArray(iFakes);
    var iCell = document.getElementsByTagName("td");

    for(c=0;c<iCell.length;c++)
    {
       with(iCell[c])
       {
          if(vAlign=="top" && align=="left" && innerHTML.match(/\d+\sGuest[s]?,\s((\d+)\sMember[s]?)/i))
          {
          
             if (navigator.appName=="Microsoft Internet Explorer") 
             {
          
                if (firstChild.innerHTML.charAt(firstChild.innerHTML.length-1)==" ")
                {
                   firstChild.innerHTML=firstChild.innerHTML.slice(0,-2);
                }
                
                var first=true;
                for(f=0;f<iFakes.length;f++)
                {
                   var iLen = iFakes.length + Math.floor(RegExp.$2);
                   var Len = (iLen == 1)? iLen + " Member" : iLen + " Members";
                   firstChild.innerHTML = innerHTML.replace(RegExp.$1,Len)
                   
                   if(iLen-iFakes.length==0 && first==true)
                   {
                      firstChild.innerHTML += '<a href="index.cgi?action=viewprofile&username=' + iFakes[f] + '">' + iFakes[f] + '</a>';
                      first=false;
                   }
                   else
                   {
                      firstChild.innerHTML += ', <a href="index.cgi?action=viewprofile&username=' + iFakes[f] + '">' + iFakes[f] + '</a>';          
                   }
                }
                
             }
             
             
             else
             {


                var first=true;
                for(f=0;f<iFakes.length;f++)
                {
                   var iLen = iFakes.length + Math.floor(RegExp.$2);
                   var Len = (iLen == 1)? iLen + " Member" : iLen + " Members";


                   if(iLen-iFakes.length==0 && first==true)
                   {
                      firstChild.innerHTML += '<a href="index.cgi?action=viewprofile&username=' + iFakes[f] + '">' + iFakes[f] + '</a>';
                      first=false;
                   }
                   else
                   {
                      firstChild.innerHTML += ', <a href="index.cgi?action=viewprofile&username=' + iFakes[f] + '">' + iFakes[f] + '</a>';          
                   }     

                }
                firstChild.innerHTML = innerHTML.replace(RegExp.$1,Len)
             
             
             }
          }
       }
    }

    function rndArray ( myArray ) 
    {
      var i = myArray.length;
      while ( i-- ) 
      {
         var j = Math.floor( Math.random() * ( i + 1 ) );
         var tempi = myArray[i];
         var tempj = myArray[j];
         myArray[i] = tempj;
         myArray[j] = tempi;
      }
    }

    //-->
    </script>

    </body>
    </html> 
    Last edited by theekid182; 01-07-2005 at 05:30 AM.

  • #9
    New Coder
    Join Date
    Jan 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've got it down to just one line that doesn't work in Netscape.
    firstChild.innerHTML = innerHTML.replace(' \,','\,');

    PHP Code:
    <!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -->
    <
    html>
    <
    head>

    <
    style type="text/css">
    <!--
    /* General layout */
    A:link        text-decorationnonecolorceeede; }
    A:visited     text-decorationnonecolorababbb; }
    A:hover       text-decorationunderline overlinecolorceeede; }
    BODY          font-familyTahoma;
                    
    font-size:12pxmargin-top0margin-left0margin-right0padding-top0padding-left0;
                    
    padding-right0; }
    TD            font-familyTahomacolorDDDDAAfont-size:11px}
    input         font-familyTahomafont-size9ptcolor000000; }
    textarea      font-familyTahomafont-size9ptcolor000000; }
    select        font-familyTahomafont-size7ptcolor000000; }

    .
    nav          font-size10pxtext-decorationnonecolorDDDDAA; }
    .
    nav:link     font-size10pxtext-decorationnonecolorceeede; }
    .
    nav:visited  font-size10pxtext-decorationnonecolorababbb; }
    .
    nav:hover    font-size10pxtext-decorationnonecolorceeedefont-weightboldtext-decorationunderline; }

    .
    windowbg     background-color203164font-size11pxfont-familyTahomacolorDDDDAA; }
    .
    windowbg2    background-color1F2369font-size11pxfont-familyTahomacolorDDDDAA; }
    .
    windowbg3    background-colorFFB903font-size11pxfont-familyTahomacolorDDDDAA; }

    .
    hr           color43478D;}
    .
    titlebg      background-color2D6F39colorDDDDAA; }
    .
    text1        font-stylenormalfont-weightboldfont-size12pxcolorDFD294; }
    .
    catbg        background-color53478DcolorDDDDAAfont-weightboldfont-size13px; }
    .
    bordercolor  background-color9DDFA9; }

    .
    quote        font-size10pxfont-familyTahomacolorDDDDAAbackground-color1F2369; }
    .
    code         font-size10pxfont-familyCourier New; colorDDDDAAbackground-color1F2369; }
    -->
    </
    style>
    <
    script language="JavaScript1.2" type="text/javascript">
    <!--
      if ((
    navigator.appVersion.substring(0,1) == "5" &&
    navigator.userAgent.indexOf('Gecko') != -1) ||
    navigator.userAgent.search(/Opera/) != -1) {
       
    document.write('<META HTTP-EQUIV="pragma" CONTENT="no-cache">');
      }
    // -->
    </script>
    </head>
    <body text="DDDDAA" bgcolor="43478D" link="ceeede" vlink="ababbb" alink="" background="http://img78.photobucket.com/albums/v298/theekid182/deep_sea4.jpg">

    <CENTER>
    <table width="92%" cellspacing="0" cellpadding="0" align="center"><!-- change celpadding from 3-->
      <tr>
        <td valign="TOP" width="100%">

    <table border=0 width="100%" cellspacing="0" cellpadding="0" bgcolor="9DDFA9" class="bordercolor">
    <tr>
    <td>
        <table cellpadding="4" cellspacing="1" border="0" width="100%">
        <tr>

        <td bgcolor="2D6F39" class="titlebg" align="center" colspan="2">
        <font class="text1" color="DDDDAA" size="2"><b>Info Center</b></font></td>
        </tr><tr>
        <td class="catbg" bgcolor="53478D" colspan="2"> <font size="2" class="cattext" color="DFD294"><b>Forum Statistics</b></font></td>
        </tr><tr>
        <td class="windowbg" bgcolor="203164" width="20" valign="middle" align="center"><IMG SRC="http://img78.photobucket.com/albums/v298/theekid182/info.gif" BORDER=0></td>
        <td class="windowbg2" bgcolor="1F2369" valign="top" align="center"><font size="1">

            <table width="98%" cellpadding="3" align="center">
            <tr>
            <td valign="top" align="left" width="60%"><font size="1">
            Total Topics: <B>1233</B> &nbsp; - &nbsp; Total Posts: <B>5273</B>
            <BR>Last Updated Topic: <B><A HREF="index.cgi?board=tech1&action=display&num=1104094027&start=0">Current Video Game Consoles</A> by <A HREF="index.cgi?action=viewprofile&username=Mp3170Counting"><B>stashkid</B></A> (<B>Today</B> at 3:13pm)</B><BR>View the <A href="index.cgi?action=recent">10 most recent posts</a> of this forum.
            </font></td>

            <td valign="top" align="left" width="40%"><font size="1">
            Total Members: <a href="index.cgi?action=mlall"><B>1107</B></a>
            <BR>Newest Member: <A HREF="index.cgi?action=viewprofile&username=lellolello4"><B>lellolello4</B></A><BR>Your Instant Messages: 
            <a href="index.cgi?action=im"><b>312</b></a> New: <a href="index.cgi?action=im"><B>0</B></a></font></td>
    </tr>
    </table>

    </font></td>
    </tr><tr>
    <td class="catbg" bgcolor="53478D" colspan="2"> <font size="2" class="cattext" color="DFD294"><b>Users Online</b></font></td>
    </tr><tr>
    <td class="windowbg" bgcolor="203164" width="20" valign="middle" align="center"><IMG SRC="http://img78.photobucket.com/albums/v298/theekid182/online.gif" BORDER=0></td>
    <td class="windowbg2" bgcolor="1F2369"><font size=1>
    <table width="98%" cellpadding="3" align="center">
    <tr>
    <td valign="top" align="left"><font size="1">9 Guests, 1 Member<BR>
    <a href="index.cgi?action=viewprofile&username=admin">Admin</a>
    </font></td>
    </tr>
    </table>

    </font></td>
    </tr>
    </table>
    </td>
    </tr>
    </table><BR>
        </td>
      </tr>
    </table>
    </CENTER>

    <script type="text/javascript">
    <!--

    // Fake users logged in
    var iFakes = [
    "admin2","admin3","admin4"
    ];

    // Scramble the array
    rndArray(iFakes);

    // Locate the InfoCenter
    var iCell = document.getElementsByTagName("td");
    for(c=0;c<iCell.length;c++)
    {
       with(iCell[c])
       {
          if(vAlign=="top" && align=="left" && innerHTML.match(/\d+\sGuest[s]?,\s((\d+)\sMember[s]?)/i)) 
          {
                // 
                var isFirstLoggedIn=true;
                for(f=0;f<iFakes.length;f++)
                {
                   // Determine the total number of members logged in
                   var iLen = iFakes.length + Math.floor(RegExp.$2);
                   var Len = (iLen == 1)? iLen + " Member" : iLen + " Members";

                   // Do not show comma before the member's name, if member is the first on the list
                   if(iLen-iFakes.length==0 && isFirstLoggedIn==true)
                   {
                      firstChild.innerHTML += '<a href="index.cgi?action=viewprofile&username=' + iFakes[f] + '">' + iFakes[f] + '</a>';
                   }
                   
                   // Otherwise, show the comma before the member's name
                   else
                   {
                      firstChild.innerHTML += ', <a href="index.cgi?action=viewprofile&username=' + iFakes[f] + '">' + iFakes[f] + '</a>';          
                   }
                   isFirstLoggedIn=false;
                }
                
                // Update the members logged-in count
                firstChild.innerHTML = innerHTML.replace(RegExp.$1,Len);
                
                // Eliminate whitespace (Does not work in Netscape)
                firstChild.innerHTML = innerHTML.replace(' \,','\,');  

                // Display Names
                firstChild.innerHTML = innerHTML.replace('Admin','theekid182');     
          }
       }
    }


    function rndArray ( tempArray ) 
    {
      var i = tempArray.length;
      while ( i-- ) 
      {
         var j = Math.floor( Math.random() * ( i + 1 ) );
         var tempi = tempArray[i];
         var tempj = tempArray[j];
         tempArray[i] = tempj;
         tempArray[j] = tempi;
      }
    }

    //-->
    </script>

    </body>
    </html> 


  •  

    Posting Permissions

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