473,322 Members | 1,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

getElementbyId Firefox v IE

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
6 28432
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
Thanks! How annoying!

Jan 25 '06 #3
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Dave Hammond | last post by:
Hi All, The following code works in IE but not Firefox. IE produces the expected "this is more text!" output, but Firefox produces "no more text". Any ideas why? <BODY> <FORM> <INPUT...
1
by: Muffinman | last post by:
Howdy, I've got here a sample of my function which is supposed to fade a certain piece of text to another colour. This line is then located in a for loop and it works pretty well in IE 6....
5
by: Derek Erb | last post by:
I am banging my head against the wall with this one. The following code snippets work perfectly fine in MSIE6. But produce an error in Firefox and do not work at all. BROWSER.HTM <HTML> .......
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
5
by: Andrea | last post by:
I am trying to alter css using javascript as well as use the innerHTML function. I have pasted below 3 forms that access getElementById in slightly different ways (I wanted to rule out that it was...
4
by: the other john | last post by:
I came across a third party script I want to learn how to configure as well as learn more dhtml in the doing. I'm not much of a JS guy yet but I'm working on it. This script works fine in IE6...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
8
by: cyqotiq | last post by:
First, let me state that this is not necessarily a Firefox problem, as I haven't fully tested in IE just yet. Second, let me state that this is not the typical "getElementById not working Firefox"...
3
by: GarryJones | last post by:
The following works in MSIE but not firefox. I suspect it has something to do with the fact that the element I am trying to access is not the "tid" which is the name of the DIV that is passed to...
1
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.