Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > getElementbyId Firefox v IE

Reply
Thread Tools

getElementbyId Firefox v IE

 
 
zippy
Guest
Posts: n/a
 
      01-25-2006
My code works fine in IE but not FF.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"
Inherits="test" %>

<!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 runat="server">
<title>Untitled Page</title>
<script>
function window_onload()
{
runTime();
setInterval(runTime, 60000);

// todo: apply png transparent style for ie < 7.0
//
filterrogidXImageTransform.Microsoft.AlphaImag eLoader(src=Images/WebDesktopIconRound.png)
}

function runTime()
{
var rightPart = document.getElementById("dvRightTemplate");
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
var temp = "";
temp += ((hour < 10) ? "0" : "")+ hour +((minute < 10) ?
":0" : ":") + minute;
rightPart.innerText = temp;
}

</script>
</head>

<body id="body" runat="server" o>
<form id="form1" runat="server">
<div>
<div id="dvRightTemplate" align="right" style="padding-right:
10px; font-size: 8pt;
width: 80px; font-family: Tahoma; color:black">
<!-- Notes: Always specify width attribute for
proper rendering in Mozilla -->
00:00</div>
</div>
</form>

</body>
</html>

 
Reply With Quote
 
 
 
 
bne
Guest
Posts: n/a
 
      01-25-2006
zippy wrote:

> My code works fine in IE but not FF.
>
> <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"
> Inherits="test" %>
>
> <!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 runat="server">
> <title>Untitled Page</title>
> <script>
> function window_onload()
> {
> runTime();
> setInterval(runTime, 60000);
>
> // todo: apply png transparent style for ie < 7.0
> //
> filterrogidXImageTransform.Microsoft.AlphaImag eLoader(src=Images/WebDesktopIconRound.png)
> }
>
> function runTime()
> {
> var rightPart = document.getElementById("dvRightTemplate");
> var time = new Date();
> var hour = time.getHours();
> var minute = time.getMinutes();
> var second = time.getSeconds();
> var temp = "";
> temp += ((hour < 10) ? "0" : "")+ hour +((minute < 10) ?
> ":0" : ":") + minute;
> rightPart.innerText = temp;
> }
>
> </script>
> </head>
>
> <body id="body" runat="server" o>
> <form id="form1" runat="server">
> <div>
> <div id="dvRightTemplate" align="right" style="padding-right:
> 10px; font-size: 8pt;
> width: 80px; font-family: Tahoma; color:black">
> <!-- Notes: Always specify width attribute for
> proper rendering in Mozilla -->
> 00:00</div>
> </div>
> </form>
>
> </body>
> </html>


Hi

innerText is specific to the IE DOM use innerHTML instead.

ben

 
Reply With Quote
 
 
 
 
zippy
Guest
Posts: n/a
 
      01-25-2006
Thanks! How annoying!

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      01-27-2006
bne wrote:
[...]
>
> innerText is specific to the IE DOM use innerHTML instead.



The DOM equivalent to IE's innerText property is textContent. Since
it's part of DOM 3, not all browsers support it but newer Gecko browsers
do (and probably others). A reasonable emulation is:

function getTextContent(el)
{
if (el.textContent) return el.textContent;
if (el.innerText) return (el.innerText);

var cNode, cNodes = el.childNodes;
var txt = '';
for (var i=0, len=cNodes.length; i<len; ++i){
cNode = cNodes[i];
if (1 == cNode.nodeType) {
txt += getTextContent(cNode);
}
if (3 == cNode.nodeType){
txt += cNode.data;
}
}
return txt;
}


Newlines may be inserted inconsistently in different browsers. Support
for other node types may be required.


--
Rob
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      01-27-2006
one man army wrote:
[...]
> also, a search in the newsgroup showed that document.getElementById()
> is not always supported. I don't know how far abck that is going. But


The FAQ offers a dynWrite function, but there is an alternative offered
here:

<URL: http://www.jibbering.com/faq/faq_not...e.html#alDynWr >


I like option 3, it is probably suitable in most cases - but read the
accompanying notes.


--
Rob
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-15-2006
RobG wrote:

> bne wrote:
> [...]
>> innerText is specific to the IE DOM use innerHTML instead.

>
> The DOM equivalent to IE's innerText property is textContent.


Unfortunately, I do not think it is. IE trims whitespace text nodes in its
DOM, so it is likely that it also trims it from the value of `innerText'.
I am not sure about that, though, since I have not IE to test with.

> Since it's part of DOM 3, not all browsers support it but newer Gecko
> browsers do (and probably others). A reasonable emulation is:
>
> function getTextContent(el)
> {
> if (el.textContent) return el.textContent;
> if (el.innerText) return (el.innerText);
> [...]


Neither will return if the element content is (considered) empty, and so
force the following code to execute. Evaluating the `typeof' operation is
more reliable here.


PointedEars
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
window getElementByID works in IE but not in FireFox --- Help! Derek Erb Javascript 5 04-17-2005 03:47 AM
Firefox & getElementById('main_txt') doesn't work Muffinman Javascript 1 03-31-2005 07:15 AM
getElementById finds an element in IE but not Firefox Dave Hammond Javascript 9 02-16-2005 09:14 AM
Firefox and getElementById Hartmut J?ger Javascript 6 11-28-2004 02:09 PM
getElementbyId problem in Firefox TR Javascript 5 05-19-2004 12:18 PM



Advertisments