By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,852 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,852 IT Pros & Developers. It's quick & easy.

getElementbyId Firefox v IE

P: n/a
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.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>

Jan 25 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
bne
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
//
filter:progid:DXImageTransform.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

Jan 25 '06 #2

P: n/a
Thanks! How annoying!

Jan 25 '06 #3

P: n/a
In article <11*********************@f14g2000cwb.googlegroups. com>,
"zippy" <jo**************@gmail.com> wrote:
Thanks! How annoying!


actually the reference I have says the neither are DOM, but both IE 4.
And as I am told ".value" is often a supported shortcut but not a real
property?

text in a div has to be scooped out. elem.firstChild.data is it in the
simple case. What a pain!
If you control the HTML that is being looked at you can make sure
there are no subElements, but you might imagine how there could be more
nested in a div.

sorry, don't shoot the msngr. I am just learning this myself.

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 compatability code that I coped is this:
// getElementById Special to handle quirky browsers
// most will use getElementById()
function getElementById_s(id){
var obj = null;
if(document.getElementById){
/* Prefer the widely supported W3C DOM method, if
available:-
*/
obj = document.getElementById(id);
}else if(document.all){
/* Branch to use document.all on document.all only
browsers. Requires that IDs are unique to the page
and do not coincide with NAME attributes on other
elements:-
*/
obj = document.all[id];
}
/* If no appropriate element retrieval mechanism exists on
this browser this function always returns null:-
*/
return obj;
}
Jan 26 '06 #4

P: n/a
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
Jan 27 '06 #5

P: n/a
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
Jan 27 '06 #6

P: n/a
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
Feb 15 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.