473,386 Members | 1,886 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,386 software developers and data experts.

Script Works in IE not FF--What am I missing?

Hi all

I have a script that works perfectly in IE but not in FF. I am sure
that the problem is easy to resolve, but I seem to be too dumb to
figure it out.

<html>

<head>
<script language="javascript">
var msgIX = 0;
var msgs = [
" Notices and Messages",
"Mad Scientist Camps are July 22 and July 29",
" Notices and Messages",
"Summer Beach Blast is August 19 ",
" Notices and Messages",
"Family Movie Night is August 25 ",
" Notices and Messages",
"Pub Night and Quiz is October 14 or 21 (TBD) ",
" Notices and Messages",
"Pot Luck Dinner is November--Exact Date TBD ",
" Notices and Messages",
"-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~"];
function scrollMessages(milliseconds) {
window.setInterval ("displayMessage()", milliseconds);
}
function displayMessage() {
if (document.getElementByID != null) {
var heading = document.getElementById("scrollme");
heading.firstChild.nodeValue = msgs[msgIX];
}else{
if(navigator.appName == "Microsoft Internet Explorer") {
var heading = document.all.item("scrollme");
heading.innerText = msgs[msgIX];
}
}
++msgIX;
msgIX %= msgs.length;
}
</script>

</head>

<body onload="scrollMessages(2000)">

<p id="scrollme">...</p>
</body>

</html>

Any assistance would be greatly appreciated. I was somehow volunteered to
create a community website, and this is one of the requested features.

DB
Jul 21 '06 #1
9 1929

DavidB wrote:
Hi all

I have a script that works perfectly in IE but not in FF. I am sure
that the problem is easy to resolve, but I seem to be too dumb to
figure it out.
"This doesn't work" is a useless message. Next time please include
details on what exactly doesn't work, what you expect to behave and
perhaps how it actually behaves.
<script language="javascript">
The language attribute is deprecated in favor of the the type
attribute:

<script type = "text/javascript">
function displayMessage() {
if (document.getElementByID != null) {
This line is the culprit. It is document.getElementById. Please note
the lowercase 'd'.
>if(navigator.appName == "Microsoft Internet Explorer") {
This is error-prone since browsers these days can spoof what they are.
Use object detection instead.
>
Any assistance would be greatly appreciated. I was somehow volunteered to
create a community website, and this is one of the requested features.

DB
This is the reason why it "doesn't work".

1. In your logic, the first if statement will always return false
because of the reason above, thus your code statements will never be
executed.
2. In your else block, the code statements will work on IE because, as
your logic indicates, the browser is IE.
3. FF doesn't work because of reason #1 + #2.

Both browsers support document.getElementById, so you can merely test
for this functionality.

if(document.getElementById)
{
//TODO: update message
}

Jul 21 '06 #2

DavidB wrote:
Hi all

I have a script that works perfectly in IE but not in FF. I am sure
that the problem is easy to resolve, but I seem to be too dumb to
figure it out.

<html>

<head>
<script language="javascript">
var msgIX = 0;
var msgs = [
" Notices and Messages",
"Mad Scientist Camps are July 22 and July 29",
" Notices and Messages",
"Summer Beach Blast is August 19 ",
" Notices and Messages",
"Family Movie Night is August 25 ",
" Notices and Messages",
"Pub Night and Quiz is October 14 or 21 (TBD) ",
" Notices and Messages",
"Pot Luck Dinner is November--Exact Date TBD ",
" Notices and Messages",
"-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~"];
function scrollMessages(milliseconds) {
window.setInterval ("displayMessage()", milliseconds);
}
function displayMessage() {
if (document.getElementByID != null) {
var heading = document.getElementById("scrollme");
heading.firstChild.nodeValue = msgs[msgIX];
}else{
if(navigator.appName == "Microsoft Internet Explorer") {
var heading = document.all.item("scrollme");
heading.innerText = msgs[msgIX];
}
}
++msgIX;
msgIX %= msgs.length;
}
</script>

</head>

<body onload="scrollMessages(2000)">

<p id="scrollme">...</p>
</body>

</html>
I don't have time at the moment to study your script in detail. However
I do see a possible problem or two. First the script does not work on
Opera either. Second, you use if(navigator.appName == "Microsoft
Internet Explorer") for detection on one leg of the else statement.
This is no longer reliable. Many browsers now come set or can be set to
spoof Microsoft Internet Explorer to avoid lockouts by such detection
done in many cases when not necessary. I believe that most recent
Mozilla family (Firefox, Netscape, Mozilla) and Opera browsers can be
and often are set to spoof Microsoft. Thirdly, and this would not cause
your problem, is we now use <script type="text/javascript"and do not
use language.

Jul 21 '06 #3
DavidB <ju******@david-baker.comwrites:
I have a script that works perfectly in IE but not in FF.
....
if (document.getElementByID != null) {
this is always false ... but it you wrote "Id" with a lower case "d",
it would work in all current browsers.
var heading = document.getElementById("scrollme");
heading.firstChild.nodeValue = msgs[msgIX];
}else{
if(navigator.appName == "Microsoft Internet Explorer") {
This else branch would then only apply to IE4.

Any assistance would be greatly appreciated. I was somehow volunteered to
create a community website, and this is one of the requested features.
Things that move by themselves is a bad idea. It makes it harder to read
for no good reason, and it makes an unnecessary dependency on javscript
for presenting text. Just put the text there.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 21 '06 #4
"cwdjrxyz" <sp*******@cwdjr.infowrote in
news:11**********************@i42g2000cwa.googlegr oups.com:
>
DavidB wrote:
>Hi all

I have a script that works perfectly in IE but not in FF. I am sure
that the problem is easy to resolve, but I seem to be too dumb to
figure it out.
<Code Stripped>
I don't have time at the moment to study your script in detail.
However I do see a possible problem or two. First the script does not
work on Opera either. Second, you use if(navigator.appName ==
"Microsoft Internet Explorer") for detection on one leg of the else
statement. This is no longer reliable. Many browsers now come set or
can be set to spoof Microsoft Internet Explorer to avoid lockouts by
such detection done in many cases when not necessary. I believe that
most recent Mozilla family (Firefox, Netscape, Mozilla) and Opera
browsers can be and often are set to spoof Microsoft. Thirdly, and
this would not cause your problem, is we now use <script
type="text/javascript"and do not use language.
Thanks to all for the help. I am not sure how to fix the issue of spoofing
IE (and I can learn that in time). The problem was fixed in the
document.getElementId typo. One correction and the text displays in both
browsers.

DB
Jul 21 '06 #5

cwdjrxyz wrote:
I don't have time at the moment to study your script in detail. However
I do see a possible problem or two. First the script does not work on
Opera either. Second, you use if(navigator.appName == "Microsoft
Internet Explorer") for detection on one leg of the else statement.
This is no longer reliable. Many browsers now come set or can be set to
spoof Microsoft Internet Explorer to avoid lockouts by such detection
done in many cases when not necessary. I believe that most recent
Mozilla family (Firefox, Netscape, Mozilla) and Opera browsers can be
and often are set to spoof Microsoft. Thirdly, and this would not cause
your problem, is we now use <script type="text/javascript"and do not
use language.
Look at http://www.cwdjr.net/test/scrollMod1.html and view the source.
The getElementById branch works perfectly well for IE6 as well as the
modern Mozilla family browsers and Opera. Thus you do not need the
document.all branch unless you want to include very old IE browsers
such as IE4. If that is a problem, then it might be possible to use
Microsoft conditional statements to write one script if the browser is
IE and another if anything else. This would be far more reliable than
attempting to detect IE with script. So far as I know, the Microsoft
conditional statement approach has not been spoofed, but it likely
could be.

Jul 21 '06 #6
DavidB wrote:
[...]
Thanks to all for the help. I am not sure how to fix the issue of spoofing
IE (and I can learn that in time).
Simple: ditch browser detection altogether:

if (document.getElementById){
/* use document.getElementById */
} else if (document.all){
/* use document.all */
}

You may want to add support for old Navigator by supporting layers, but
maybe not. Read the FAQ:

<URL:http://www.jibbering.com/faq>

--
Rob

Jul 21 '06 #7

RobG wrote:
DavidB wrote:
[...]
Thanks to all for the help. I am not sure how to fix the issue of spoofing
IE (and I can learn that in time).

Simple: ditch browser detection altogether:

if (document.getElementById){
/* use document.getElementById */
} else if (document.all){
/* use document.all */
}
Of course IE6 supports both document.getElementById and document.all,
and IE4 supports only document.all. If the document.getElementById leg
also works properly on IE5, which it should but which I can not test
for lack of IE5, then a more elegant way might be to route to the
document.getElementById path if both document.getElementById and
document.all are supported and route to a document.all path if only it
is supported.

Of course, if one wanted to support ancient relic browsers, one might
use an alternate path to do something else. I fail to see the need to
go to the trouble of supporting IE4, Netscape4, and earlier browsers,
but there could still be a few small areas of the world where such
support might still be of use. I know that where I live that such old
relic browsers would not allow me into my bank site, important
government sites, many shopping sites, or my broker. Also they will not
work on many important news and media sites.
You may want to add support for old Navigator by supporting layers, but
maybe not. Read the FAQ:

<URL:http://www.jibbering.com/faq>

--
Rob
Jul 22 '06 #8
cwdjrxyz wrote:
RobG wrote:
>DavidB wrote:
[...]
>>Thanks to all for the help. I am not sure how to fix the issue of spoofing
IE (and I can learn that in time).
Simple: ditch browser detection altogether:

if (document.getElementById){
/* use document.getElementById */
} else if (document.all){
/* use document.all */
}

Of course IE6 supports both document.getElementById and document.all,
and IE4 supports only document.all. If the document.getElementById leg
also works properly on IE5, which it should but which I can not test
for lack of IE5, then a more elegant way might be to route to the
document.getElementById path if both document.getElementById and
document.all are supported and route to a document.all path if only it
is supported.
That seems confused - what about browsers that support getElementById
but not document.all?

The *only* reason to test for document.all is as a fall-back if
document.getElementById is not supported. If the latter is supported
(which it is in perhaps 99.9% of browsers in use), there is no need to
test for the former.
[...]
--
Rob
Jul 22 '06 #9

RobG wrote:
cwdjrxyz wrote:
RobG wrote:
DavidB wrote:
[...]
Thanks to all for the help. I am not sure how to fix the issue of spoofing
IE (and I can learn that in time).
Simple: ditch browser detection altogether:

if (document.getElementById){
/* use document.getElementById */
} else if (document.all){
/* use document.all */
}
Of course IE6 supports both document.getElementById and document.all,
and IE4 supports only document.all. If the document.getElementById leg
also works properly on IE5, which it should but which I can not test
for lack of IE5, then a more elegant way might be to route to the
document.getElementById path if both document.getElementById and
document.all are supported and route to a document.all path if only it
is supported.

That seems confused - what about browsers that support getElementById
but not document.all?

The *only* reason to test for document.all is as a fall-back if
document.getElementById is not supported. If the latter is supported
(which it is in perhaps 99.9% of browsers in use), there is no need to
test for the former.
I see what you are talking about. I failed to notice that your test for
document.all was an "else if" rather than just "else", which makes a
considerable difference. Still I can see a few cases where one might
want a more extensive test. Besides IE, even recent Opera browsers will
support document.all in addition to getElementById. I doubt if there
ever was an early Opera browser that only supported document.all, but
since I had no experience with them, I could not say for sure. Also
earlier versions of WebTV supported only document.all - or at least
some parts of it. The point is that it can not be assumed that one is
dealing with an IE browser if it supports document.all with or without
document.getElementById support. At least in the case of WebTV one
could test for appCodeName. For most computer browsers, this returns
Mozilla, which is not at all useful. However WebTV returned "bowser",
which allowed you provide a special path for WebTV to overcome the many
things it did not support.

In a few cases, the Microsoft html conditional comment also can be
useful. Such a comment appears as just an ordinary comment to most
browsers, but Microsoft browsers can see through the comment tags to
view code within. This becomes more interesting when one notices that
Microsoft conditional comments can be used to write one script when the
browser is Microsoft and another when it is not. This approach can be
useful when one wishes to use some of the many IE specific codes only
if one is viewed by an IE browser and use something else for other
browsers. I have used such an approach to allow Microsoft to use an
ActiveX WMP object for playing certain media files, and for using an
ordinary object for other browsers which often do not support ActiveX.
I found one case when a video file would start streaming at once on
most browsers using an ordinary object, but it would not stream until
completly downloaded on IE6. Allowing the ActiveX object for IE only
corrected this problem, and streaming started at once. So far as I
know, the Microsoft conditional comment has not been spoofed, but it
likely could be if other browser writers wanted to.

Jul 22 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jonezy | last post by:
my test server is win2k server, the script works fine, loads the movie, allows user selection etc. however when i access the same script on my remote server none of the requesting files load. the...
3
by: Andy Stevenson | last post by:
Hi, As subject, I have the following JS in my HTML document & it works fine: <SCRIPT type="text/JavaScript"> <!-- COPYRIGHT = " : Copyright &copy; Diverse Arts., 2003-"; function...
1
by: lendle | last post by:
Hello, I have some javascript on local disk, they work fine on mozilla browsers and event work when I put the html into hta format. However, the code does not work on IE of my computer. I've...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
3
by: cjl | last post by:
Hey all: Just getting my feet wet with javascript. The following script works fine in Firefox, but won't run in IE. In fact, I've included this script as an external file in the <head> of my...
10
by: lawrence k | last post by:
I've got a script called makeRss.php. It works fine if I try to open it with my browser. It makes an RSS feed for every page on my site. You can see it working here: ...
2
by: ranger7419 | last post by:
I'm trying to figure out why this script will work in IE 6 but not Firefox, and so I need someone here with a far better grasp on javascript to explain this. Basically, I have a page with several...
3
tolkienarda
by: tolkienarda | last post by:
hi all i have a problem i have a script that i got working exactly the way i wanted it. and then i tried to intrigate it into the site and it totaly stopped working. below is the original code ...
1
by: -Lost | last post by:
This is more of a post to inform, unless of course I am missing something fundamental, in which case I would appreciate anyone explaining it. Based on Mr. Michaux's camelizeStyle function I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.