getElementbyId Firefox v IE

Z

zippy

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
//
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(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>
 
B

bne

zippy said:
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
//
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(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
 
R

RobG

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;
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.
 
T

Thomas 'PointedEars' Lahn

RobG said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top