开发者

GetElementByID Problem in Chrome and IE

This code fails in IE and Chrome on the following line:

top.document.getElementById('LikeStatusBar' + statusid).innerHTML = ' ';

this code works perfectly in firefox 4. The AJAX ASP Page like_status.asp works flawlessly and just returns some HTML code to be displayed in the page.

Here is the complete javascript code:

function LikeSU(statusid,option,mediaid)
{
     if (option == 'l')
     {
          document.getElementById('fmeProcess').src = '/ajax/like_unlike.asp?statusid=' + statusid + '&mediaid=' + mediaid + '&option=' + option;
          document.getElementById('StatusLike' + statusid).innerHTML = '&nbsp;&middot; <a href="javascript:void(0)" onclick="LikeSU(' + statusid + ',\'u\')">Unlike</a>'
          GetLikeDisplay(statusid);
     }
     else
     {
          document.getElementById('fmeProcess').src = '/ajax/like_unlike.asp?statusid=' + statusid + '&mediaid=' + mediaid + '&option=' + option;
          document.getElementById('StatusLike' + statusid).innerHTML = '&nbsp;&middot; <a href="javascript:void(0)" onclick="LikeSU(' + statusid + ',\'l\')">Like</a>'
          GetLikeDisplay(statusid);
     }
}

function GetLikeDisplay(statusid)
{
     var xmlHttp = GetXmlHttpObject();
     var url="/ajax/like_status.asp?statusid=" + statusid
     if (!xmlHttp){
          alert ("Browser does not support HTTP Request")
          return
     }
     xmlHttp.onreadystatechange=function()
     {
          if (xmlHttp.readyState == 1)
          {
               top.document.getElementById('LikeStatusBar' + statusid).innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tr><td style="padding-left:5px"><img src="/images/register_loading.gif" alt="Loading"/></td><td style="color:#c0c0c0;padding-left:8px">Loading...</td></tr></table>';
          }
          if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
          {
               if(xmlHttp.responseText == "NoLikes")
               {
                    top.document.getElementById('LikeStatusBar' + statusid).innerHTML = '&nbsp;';
                    top.document.getElementById('LikeCountDisplay' + statusid).style.display = 'none';
                    top.document.getElementById('LikeStatusBar' + statusid + 'Gap').style.display = 'none';
               }
               else
               {
                    top.document.getElementById('LikeStatusBar' + statusid).innerHTML = xmlHttp.responseText;
                    top.document.getElementById('LikeCountDisplay' + statusid).style.display = '';
                    top.document.getElementById('LikeStatusBar' + statusid + 'Gap').style.display = '';
               }
          }
     };
     xmlHttp.open("GET", url , true)
     xmlHttp.send(null)
}

function GetXmlHttpObject()
{
     var objXMLHttp=null;
     if (window.XMLHttpRequest)
     {
          objXMLHttp=new XMLHttpRequest();
     }
     else if (window.ActiveXObject)
     {
          objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
     }
     return objXMLHttp;
}

any ideas as to how I can fix this problem in IE and Chrome..

Many thanks in advance, Paul

ADDED CODE

 <!--#include virtual="/inc/global.asp"-->
 <% IF NOT UserIsLoggedIn() THEN %>
 <script language="javascript" type="text/javascript">
 top.parent.location.href = '/';
 </script>
 <% END IF %>
 <!--#include virtual="/inc/adovbs.inc"-->
 <!--#include virtual="/inc/common.inc"-->
 <%
 Dim pstrOut, MemberID, paryFriendStatus, StatusUpdate
 cData.SQL = "sp_MemberConnection " _
           & cData.ProcFld("MODE","RECENTFRIENDUSERSTATUSPOSTS",2,True) _
           & cData.ProcFld("MemberID",cSession.MemberID,0,False)
 paryFriendStatus = cData.RSArray()

 IF isArray(paryFriendStatus) THEN
   pstrOut = "<table border=""0"" width=""555"" cellspacing=""0"" cellpadding=""0"">" & vbCr
   FOR i = 0 TO uBound(paryFriendStatus,2)
     pstrOut = pstrOut & "<tr id=""MemberStatus" & paryFriendStatus(5,i) & """>" & vbCr _
             & "<td style=""padding:4px 0px 4px 0px"">" & vbCr _
             & "<table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""100%"">" & vbCr _
             & "<tr>" & vbCr
     IF ISNULL(paryFriendStatus(6,i)) THEN
       pstrOut = pstrOut & "<td style=""width: 75px"" valign=""top"" align=""center"">" & GetMemberAvatar(paryFriendStatus(0,i),C_SMALLAVATAR,True,True) & "</td>" & vbCr
     ELSE
       pstrOut = pstrOut & "<td style=""width: 75px"" valign=""top"" align=""center"">" & GetMemberAvatar(paryFriendStatus(6,i),C_SMALLAVATAR,True,True)  & "</td>" & vbCr
     END IF
     pstrOut = pstrOut & "<td valign=""top"" class=""mainlink f5"">" & vbCr _
             & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:100%"">" & vbCr _
             & "<tr>" & vbCr
     IF paryFriendStatus(2,i) = "has joined Storeboard!" OR paryFriendStatus(2,i) = "joined Storeboard!" THEN
       StatusUpdate = DisplayName(paryFriendStatus(0,i)) & " joined Storeboard!"
     ELSE
       StatusUpdate = paryFriendStatus(2,i)
     END IF
     IF ISNULL(paryFriendStatus(6,i)) THEN
       pstrOut = pstrOut & "<td style=""font-size:13px""><b style=""color:#0389BB"">" & MemberLink(paryFriendStatus(0,i),"BlueLink1") & ":</b>&nbsp;<span class=""mainlink-u"">" & FindLinks(StatusUpdate) & "</span></td>" & vbCr
     ELSE
       pstrOut = pstrOut & "<td style=""font-size:13px"">" & vbCr _
               & "<div style=""float:left"">" & vbCr _
               & "<table cellpadding=""0"" cellspacing=""0"" border=""0"">" & vbCr _
               & "<tr>" & vbCr _
               & "<td><b style=""color:#0389BB"">" & MemberLink(paryFriendStatus(6,i),"BlueLink1") & "</b></td>" & vbCr _
               & "<td style=""padding:0px 4px 0px 4px""><img src=""/images/m2b_arrow.gif"" alt=""Arrow""/></td>" & vbCr _
               & "<td><b style=""color:#0389BB"">" & MemberLink(paryFriendStatus(0,i),"BlueLink1") & ":</b>&nbsp;</td>" & vbCr _
               & "</tr></table></div>" & vbCr _
               & "<div style=""float:left""><span class=""mainlink-u"">" & FindLinks(StatusUpdate) & "</span></div></td>" & vbCr
     END IF
     pstrOut = pstrOut & "</tr>" & vbCr

     SET DbConn = Server.CreateObject("ADODB.connection")
     DbConn.Open DSN_LINK

     SET oRSbn = Server.CreateObject("ADODB.recordset")
     strSQLCount = "SELECT count(*) as comment_count FROM StatusComments WHERE MemberStatusID = " & paryFriendStatus(5,i) & ";"
     oRSbn.open strSQLCount, DbConn
     nTotalComments = oRSbn("comment_count")
     oRSbn.Close

     IF cSession.MemberID = "33" OR cSession.MemberID = "102" THEN
       IF FetchLikeStatus(cSession.MemberID,paryFriendStatus(5,i)) = "" THEN
         pstrOut = pstrOut & "<tr style=""height:25px"">" & vbCr _
                 & "<td class=""mainlink f5""><span style=""color:#808080"">" & HowLongAgo(paryFriendStatus(4,i))  & "</span><span id=""StatusLike" & paryFriendStatus(5,i) & """>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""LikeSU(" & paryFriendStatus(5,i) & ",'l')"">Like</a></span>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ShowCommentBox(" & paryFriendStatus(5,i) & ")"">Comment</a>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ConfirmStatusRemoval(" & paryFriendStatus(5,i) & ")"">Remove</a>" & vbCr
       ELSE
         pstrOut = pstrOut & "<tr style=""height:25px"">" & vbCr _
                 & "<td class=""mainlink f5""><span style=""color:#808080"">" & HowLongAgo(paryFriendStatus(4,i))  & "</span><span id=""StatusLike" & paryFriendStatus(5,i) & """>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""LikeSU(" & paryFriendStatus(5,i) & ",'u')"">Unlike</a></span>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ShowCommentBox(" & paryFriendStatus(5,i) & ")"">Comment</a>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ConfirmStatusRemoval(" & paryFriendStatus(5,i) & ")"">Remove</a>" & vbCr
       END IF
       IF nTotalComments > 3 THEN
         pstrOut = pstrOut & "&nbsp;&middot; <a href=""#"">View all " & nTotalComments & " comments</a>" & vbCr
       END IF
       pstrOut = pstrOut & "</td>" & vbCr _
               & "</tr>" & vbCr
     ELSE
       IF FetchLikeStatus(cSession.MemberID,paryFriendStatus(5,i)) = "" THEN
         pstrOut = pstrOut & "<tr style=""height:25px"">" & vbCr _
                 & "<td class=""mainlink f5""><span style=""color:#808080"">" & HowLongAgo(paryFriendStatus(4,i))  & "</span><span id=""StatusLike" & paryFriendStatus(5,i) & """>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""LikeSU(" & paryFriendStatus(5,i) & ",'l')"">Like</a></span>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ShowCommentBox(" & paryFriendStatus(5,i) & ")"">Comment</a>" & vbCr
       ELSE
         pstrOut = pstrOut & "<tr style=""height:25px"">" & vbCr _
                 & "<td class=""mainlink f5""><span style=""color:#808080"">" & HowLongAgo(paryFriendStatus(4,i))  & "</span><span id=""StatusLike" & paryFriendStatus(5,i) & """>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""LikeSU(" & paryFriendStatus(5,i) & ",'u')"">Unlike</a></span>&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ShowCommentBox(" & paryFriendStatus(5,i) & ")"">Comment</a>" & vbCr
       END IF
       IF cLng(paryFriendStatus(0,i)) = cLng(cSession.MemberID) THEN
         pstrOut = pstrOut & "&nbsp;&middot; <a href=""javascript:void(0)"" onclick=""ConfirmStatusRemoval(" & paryFriendStatus(5,i) & ")"">Remove</a>" & vbCr
       END IF
       IF nTotalComments > 3 THEN
         pstrOut = pstrOut & "&nbsp;&middot; <a href=""#"">View all " & nTotalComments & " comments</a>" & vbCr
       END IF
       pstrOut = pstrOut & "</td></tr>" & vbCr
     END IF
     Set ShowComments = Server.CreateObject("ADODB.recordset")
     IF nTotalComments >= 3 THEN
       nNumToShow = 3
     ELSEIF nTotalComments = 2 THEN
       nNumToShow = 2
     ELSE
       nNumToShow = 1
     END IF

     ' SHOW LIKE COUNTER
     IF CountStatusLikes(paryFriendStatus(5,i)) > 0 THEN
       pstrOut = pstrOut & "<tr id=""LikeCountDisplay" & paryFriendStatus(5,i) & """>" & vbCr
     ELSE
       pstrOut = pstrOut & "<tr id=""LikeCountDisplay" & paryFriendStatus(5,i) & """ style=""display:none"">" & vbCr
     END IF
     pstrOut = pstrOut & "<td>" & vbCr _
             & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:350px"">" & vbCr _
             & "<tr style=""background-color:#EAF6F6"" id=""LikeStatusBar" & paryFriendStatus(5,i) & """>" & vbCr
     IF CountStatusLikes(paryFriendStatus(5,i)) > 0 THEN
       IF FetchLikeStatus(cSession.MemberID,paryFriendStatus(5,i)) = "" THEN
         IF CountStatusLikes(paryFriendStatus(5,i)) = 1 THEN
           pstrOut = pstrOut & "<td style=""padding:5px;border-bottom:1px #D8EEEE solid""><table cellpadding=""0"" cellspacing=""0"" border=""0""><tr><td><img src=""/images/thumbup_blue.gif"" alt=""Likes""/></td><td style=""padding-left:5px"" class=""f5 mainlink""><a href=""" & MemberURL(FetchOneLikeMember(paryFriendStatus(5,i))) & """>" & DisplayName(FetchOneLikeMember(paryFriendStatus(5,i))) & "</a> Likes This.</td></tr></table>" & vbCr
         ELSE
           pstrOut = pstrOut & "<td style=""padding:5px;border-bottom:1px #D8EEEE solid""><table cellpadding=""0"" cellspacing=""0"" border=""0""><tr><td><img src=""/images/thumbup_blue.gif"" alt=""Likes""/></td><td style=""padding-left:5px"" class=""f5"">" & CountStatusLikes(paryFriendStatus(5,i)) & " Members Like This.</td></tr></table>" & vbCr
         END IF
       ELSE
         IF CountStatusLikes(paryFriendStatus(5,i)) = 1 THEN
           pstrOut = pstrOut & "<td style=""padding:5px;border-bottom:1px #D8EEEE solid""><table cellpadding=""0"" cellspacing=""0"" border=""0""><tr><td><img src=""/images/thumbup_blue.gif"" alt=""Likes""/></td><td style=""padding-left:5px"" class=""f5"">You Like This</td></tr></table>" & vbCr
         ELSEIF CountStatusLikes(paryFriendStatus(5,i)) = 2 THEN
           pstrOut = pstrOut & "<td style=""padding:5px;border-bottom:1px #D8EEEE solid""><table cellpadding=""0"" cellspacing=""0"" border=""0""><tr><td><img src=""/images/thumbup_blue.gif"" alt=""Likes""/></td><td style=""padding-left:5px"" class=""f5"">You And <a href=""" & MemberURL(FetchOneLikeMember(paryFriendStatus(5,i))) & """>" & DisplayName(FetchOneLikeMember(paryFriendStatus(5,i))) & "</a> Like This.</td></tr></table>" & vbCr
         ELSE
           pstrOut = pstrOut & "<td style=""padding:5px;border-bottom:1px #D8EEEE solid""><table cellpadding=""0"" cellspacing=""0"" border=""0""><tr><td><img src=""/images/thumbup_blue.gif"" alt=""Likes""/></td><td style=""padding-left:5px"" class=""f5"">You And " & CountStatusLikes(paryFriendStatus(5,i)) - 1 & " Members Likes This.</td></tr></table>" & vbCr
         END IF
       END IF
       pstrOut = pstrOut & "</td></tr>" & vbCr
       IF CountStatusLikes(paryFriendStatus(5,i)) > 0 THEN
         pstrOut = pstrOut & "<tr style=""height:2px;background-color:#FFFFFF"" id=""LikeStatusBar" & paryFriendStatus(5,i) & "Gap"">" & vbCr
       ELSE
         pstrOut = pstrOut & "<tr style=""height:2px;background-color:#FFFFFF;display:none"" id=""LikeStatusBar" & paryFriendStatus(5,i) & "Gap"">" & vbCr
       END IF
       pstrOut = pstrOut & "<td></td></tr></table></td></tr>" & vbCr
     ELSE
       pstrOut = pstrOut & "<td style=""padding:5px;border-bottom:1px #D8EEEE solid"">&nbsp;</td></tr>" & vbCr _
               & "<tr style=""height:2px;background-color:#FFFFFF;display:none"" id=""LikeStatusBar" & paryFriendStatus(5,i) & "Gap"">" & vbCr _
               & "<td></td></tr></table></td></tr>" & vbCr
     END IF

     strSQL = "SELECT TOP " & nNumToShow & " * FROM StatusComments WHERE MemberStatusID = " & paryFriendStatus(5,i) & " ORDER BY StatusCommentTime ASC;"
     ShowComments.open strSQL, DbConn
     IF NOT ShowComments.EOF THEN
       ShowComments.MoveFirst
       Do while NOT ShowComments.EOF
         pstrOut = pstrOut & "<tr id=""StatusComment" & ShowComments("StatusCommentID") & """>" & vbCr _
                 & "<td>" & vbCr _
                 & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:350px"">" & vbCr _
                 & "<tr style=""background-color:#EAF6F6"">" & vbCr _
                 & "<td style=""padding-top:4px;width:50px"" align=""center"" valign=""top"">" & GetMemberAvatar(ShowComments("MemberID"),C_TINYAVATAR,False,False) & "</td>" & vbCr _
                 & "<td valign=""top"" style=""padding:3px 4px 3px 0px"">" & vbCr _
                 & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:100%"">" & vbCr _
                 & "<tr>" & vbCr _
                 & "<td><b style=""color:#0389BB"">" & MemberLink(ShowComments("MemberID"), "BlueLink1") & ":</b>&nbsp;&nbsp;" & FindLinks(ShowComments("StatusComment")) & "</td>" & vbCr _
                 & "</tr>" & vbCr _
                 & "<tr>" & vbCr _
                 & "<td style=""color:#777777"">" & HowLongAgo(ShowComments("StatusCommentTime"))
         IF cLng(paryFriendStatus(0,i)) = cLng(cSession.MemberID) OR cLng(ShowComments("MemberID")) = cLng(cSession.MemberID) THEN
           pstrOut = pstrOut & "&nbsp;&middot; <a href=""#"" onclick=""ConfirmStatusCommentDelete(" & ShowComments("StatusCommentID") & ")"">Delete</a>" & vbCr
         END IF
         pstrOut = pstrOut & "</td>" & vbCr _
                 & "</tr>" & vbCr _
                 & "</table>" & vbCr _
                 & "</td>" & vbCr _
                 & "</tr>" & vbCr _
                 & "<tr style=""height:2px;background-color:#FFFFFF"">" & vbCr _
                 & "<td></td>" & vbCr _
                 & "</tr>" & vbCr _
                 & "</table>" & vbCr _
                 & "</td>" & vbCr _
                 & "</tr>" & vbCr
         ShowComments.movenext开发者_JAVA技巧
       loop
     END IF
     ShowComments.Close
     SET ShowComments = Nothing
     SET DbConn = Nothing
     pstrOut = pstrOut & "<tr style=""display:none"" id=""ShowComment" & paryFriendStatus(5,i) & """>" & vbCr _
             & "<td>" & vbCr _
             & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:350px"">" & vbCr _
             & "<tr style=""background-color:#EAF6F6"">" & vbCr _
             & "<td style=""padding-top:4px;width:50px"" align=""center"" valign=""top"">" & GetMemberAvatar(cSession.MemberID,C_TINYAVATAR,False,False) & "</td>" & vbCr _
             & "<td valign=""top"" style=""padding:4px 4px 4px 0px"">" & vbCr _
             & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:100%"">" & vbCr _
             & "<tr>" & vbCr _
             & "<td id=""Comment" & paryFriendStatus(5,i) & """></td>" & vbCr _
             & "</tr>" & vbCr _
             & "<tr>" & vbCr _
             & "<td style=""color:#777777"" id=""CommentTime" & paryFriendStatus(5,i) & """></td>" & vbCr _
             & "</tr>" & vbCr _
             & "</table>" & vbCr _
             & "</td>" & vbCr _
             & "</tr>" & vbCr _
             & "</table>" & vbCr _
             & "</td>" & vbCr _
             & "</tr>" & vbCr _
             & "<tr>" & vbCr _
             & "<td>" & vbCr _
             & "<form action="""" method=""post"" name=""frmStatusComment" & paryFriendStatus(5,i) & """>" & vbCr _
             & "<input type=""hidden"" value=""" & cSession.MemberID & """ name=""hidMemberID" & paryFriendStatus(5,i) & """/>" & vbCr _
             & "<table cellpadding=""4"" cellspacing=""0"" border=""0"" style=""width:350px"" id=""nocomment" & paryFriendStatus(5,i) & """>" & vbCr _
             & "<tr style=""background-color:#EAF6F6"">" & vbCr _
             & "<td align=""center""><input type=""text"" onclick=""ShowCommentBox(" & paryFriendStatus(5,i) & ")"" style=""padding-left:3px;height:20px;width:337px;border:1px #C6E7E7 solid;color:#808080"" class=""f5"" value=""Write a Comment!""/></td>" & vbCr _
             & "</tr>" & vbCr _
             & "</table>" & vbCr _
             & "<table cellpadding=""0"" cellspacing=""0"" border=""0"" style=""width:350px;display:none"" id=""yescomment" & paryFriendStatus(5,i) & """>" & vbCr _
             & "<tr style=""background-color:#EAF6F6"">" & vbCr _
             & "<td style=""padding-top:4px;width:50px"" align=""center"" valign=""top"">" & GetMemberAvatar(cSession.MemberID,C_TINYAVATAR,False,False) & "</td>" & vbCr _
             & "<td valign=""top"" style=""padding:4px 4px 0 0""><textarea id=""taStatusComments" & paryFriendStatus(5,i) & """ name=""taStatusComments" & paryFriendStatus(5,i) & """ onblur=""ShowCommentBox(" & paryFriendStatus(5,i) & ")"" style=""padding:3px;width:290px;border:1px #C6E7E7 solid"" class=""f5"" cols="""" rows=""""></textarea></td>" & vbCr _
             & "</tr>" & vbCr _
             & "<tr style=""background-color:#EAF6F6"">" & vbCr _
             & "<td colspan=""2"" align=""right""><button type=""button"" class=""smlBtn"" name=""btnUpdate"" onclick=""return SaveStatusComments(" & paryFriendStatus(5,i) & ")""><span class=""sBtn""><span class=""sBtn"">Comment</span></span></button></td>" & vbCr _
             & "</tr></table></form></td></tr></table></td></tr></table></td></tr>" & vbCr _
             & "<tr id=""MemberStatus" & paryFriendStatus(5,i) & "spacer"" style=""height:1px"">" & vbCr _
             & "<td style=""background-color:#E9E9E9""><img src=""/images/pixel.gif"" alt=""""/></td></tr>" & vbCr
   NEXT
   pstrOut = pstrOut & "</table>" & vbCr
   'Response.Write pstrOut
   'Response.End
 END IF %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
 <title>Untitled Page</title>
 <script language="javascript" type="text/javascript">
 <!--
 var target = top.parent.document.getElementById('fmeFriendStatus');
 var jstr = '';
 <%=cUtil.ToJS(pstrOut,"jstr")%>
 target.innerHTML = jstr;
 //-->
 </script>
 </head>
 <body>
 </body>
 </html>

This html page is ran in an iframe.. The majority is Classic ASP hence the double ""


Can you try using 'window.top...'

instead of

'top....'

Some browsers are really strict in the DOM naming hierarchy.


You can use top.document.all.elementName in IE. it works. But the problem cannot work in Firefox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜