PDA

View Full Version : Javascript works in IE...but Not Mozilla..


ManagerJosh
Tue 4th Jan '05, 8:06am
Can someone figure out what I did wrong with these few lines of Javascript? They work in IE, but don't work in Mozilla...gahh!! :mad: :mad: :mad: :mad:

<script LANGUAGE="JavaScript">
<!--
current = 0;
layName='test';
// Hour * 60 * 60 + Minute * 60 + Sec
time1 = 4 * 60 * 60;
time2 = 10 * 60 * 60;
time3 = 16 * 60 * 60;
time4 = 20 * 60 * 60;
// current display images Number.

disp = 0;
function setBG() {
now = new Date();
h = now.getHours();
m = now.getMinutes();
s = now.getSeconds();
time = s + m * 60 + h * 60 * 60; // date to sec trans.
</script>

MrNase
Tue 4th Jan '05, 9:51am
<script type="text/javascript">
<!--
var current = 0;
var layName = "test";
// Hour * 60 * 60 + Minute * 60 + Sec
var time1 = 4 * 60 * 60;
var time2 = 10 * 60 * 60;
var time3 = 16 * 60 * 60;
var time4 = 20 * 60 * 60;
// current display images Number.

var disp = 0;
function setBG() {
var now = new Date();
var h = now.getHours();
var m = now.getMinutes();
var s = now.getSeconds();
var time = s + m * 60 + h * 60 * 60; // date to sec trans.

return time;
}


alert(setBG());

alert(time1);
alert(time2);
alert(time3);
alert(time4);
// -->

</script>

ManagerJosh
Tue 4th Jan '05, 1:08pm
Thanks Nase, but Mozilla still isn't rendering it properly. It still keeps processing it as time1 = 4 * 60 * 60;

Actually, I just noticed after more testing...it doesn't even render it properly now... :-/

It just observes Time1. and doesn't observe the rest.

ManagerJosh
Tue 4th Jan '05, 2:20pm
here's the complete HTML set...

<?xml version="1.0" encoding="iso-8859-1"?>
<!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>
<script language="javascript" type="text/javascript" >
current = 0;
layName = 'test';
// Hour * 60 * 60 + Minute * 60 + Sec
time1 = 4 * 60 * 60;
time2 = 10 * 60 * 60;
time3 = 16 * 60 * 60;
time4 = 20 * 60 * 60;
// current display images Number.

disp = 0;

function setBG() {
now = new Date();
h = now.getHours();
m = now.getMinutes();
s = now.getSeconds();
time = s + m * 60 + h * 60 * 60; // date to sec trans.

if (time > time4) {
if (document.all && disp != 5) {
dawn.style.display = 'none';
daytime.style.display = 'none';
sunset.style.display = 'none';
midnight.style.display = '';
disp = 5;
}
}
else if (time > time3) {
if (document.all && disp != 4) {
dawn.style.display = 'none';
daytime.style.display = 'none';
sunset.style.display = '';
midnight.style.display = 'none';
disp = 4;
}
} else if (time > time2) {
if (document.all && disp != 3) {
dawn.style.display = 'none';
daytime.style.display = '';
sunset.style.display = 'none';
midnight.style.display = 'none';
disp = 3;
}
} else if (time > time1) {
if (document.all && disp != 2) {
dawn.style.display = '';
daytime.style.display = 'none';
sunset.style.display = 'none';
midnight.style.display = 'none';
disp = 2;
}
}
else {
if (document.all && disp != 5) {
dawn.style.display = 'none';
daytime.style.display = 'none';
sunset.style.display = 'none';
midnight.style.display = '';
disp = 5;
}
}
setTimeout('setBG()', 60000);
}
// -->
</script>
<title>VAIOscape</title>
</head>
<body onload="setBG()" bgcolor="#A6CAF0" text="#FFFFFF" link="#FFFF00" vlink="#C0C0C0" alink="#FF0000" leftmargin="0" topmargin="0">
<div id="dawn" style="position:absolute;left:0px;top:0px; width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet code="Lake.class" width="1024" height="768">
<param name="image" value="VAIOscape_dawn.jpg" />
<param name="overlay" value="" />
</applet></center>
</div>
<div id="daytime" style="display:none;position:absolute;left:0px;top:0px; width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet code="Lake.class" width="1024" height="768">
<param name="image" value="VAIOscape_daytime.jpg" />
<param name="overlay" value="" />
</applet></center>
</div>
<div id="sunset" style="display:none;position:absolute;left:0px;top:0px; width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet code="Lake.class" width="1024" height="768">
<param name="image" value="VAIOscape_sunset.jpg" />
<param name="overlay" value="" />
</applet></center>
</div>
<div id="midnight" style="display:none;position:absolute;left:0px;top:0px; width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet code="Lake.class" width="1024" height="768">
<param name="image" value="VAIOscape_midnight.jpg" />
<param name="overlay" value="" />
</applet></center>
</div>
</body>
</html>

ManagerJosh
Thu 6th Jan '05, 4:58am
Bump to the left.. bump to the right...bump it here...bump it there... ;)

ManagerJosh
Wed 12th Jan '05, 6:59am
nobody?

diades
Wed 12th Jan '05, 7:05pm
Hi Josh

You are trying to reference objects directly via their identifier which is fine in IE but no other browser. Use document.getElementById("[identifier]").blah

ManagerJosh
Tue 18th Jan '05, 2:33am
Revisiting this...doesn't seem to work in mozilla..

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script LANGUAGE="JavaScript">
<!--
current = 0;
layName='test';
// Hour * 60 * 60 + Minute * 60 + Sec
time1 = 4 * 60 * 60; // dawn
time2 = 10 * 60 * 60; // daytime
time3 = 16 * 60 * 60; // sunset
time4 = 20 * 60 * 60; // midnight
// current display images Number.
disp = 0;
function setBG() {
now = new Date();
h = now.getHours();
m = now.getMinutes();
s = now.getSeconds();
time = s + m * 60 + h * 60 * 60; // date to sec trans.

if (time > time4) {
if (document.all && disp != 5) {
document.getElementById("dawn").style.display = 'none';
document.getElementById("daytime").style.display = 'none';
document.getElementById("sunset").style.display = 'none';
document.getElementById("midnight").style.display = '';
disp = 5;
}
}
else if (time > time3) {
if (document.all && disp != 4) {
document.getElementById("dawn").style.display = 'none';
document.getElementById("daytime").style.display = 'none';
document.getElementById("sunset").style.display = '';
document.getElementById("midnight").style.display = 'none';
disp = 4;
}
} else if (time > time2) {
if (document.all && disp != 3) {
document.getElementById("dawn").style.display = 'none';
document.getElementById("daytime").style.display = '';
document.getElementById("sunset").style.display = 'none';
document.getElementById("midnight").style.display = 'none';
disp = 3;
}
} else if (time > time1) {
if (document.all && disp != 2) {
document.getElementById("dawn").style.display = '';
document.getElementById("daytime").style.display = 'none';
document.getElementById("sunset").style.display = 'none';
document.getElementById("midnight").style.display = 'none';
disp = 2;
}
}
else {
if (document.all && disp != 5) {
document.getElementById("dawn").style.display = 'none';
document.getElementById("daytime").style.display = 'none';
document.getElementById("sunset").style.display = 'none';
document.getElementById("midnight").style.display = '';
disp = 5;
}
}
setTimeout('setBG()', 60000);
}
// -->
</script>
<title>VAIOscape</title>
</head>
<body onLoad="setBG()" topmargin="0" leftmargin="0" bgcolor="#A6CAF0" TEXT="#FFFFFF" LINK="#FFFF00" VLINK="#C0C0C0" ALINK="#FF0000">
<div ID="dawn"
STYLE="display:none;position:absolute;left:0px;top:0px;
width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet
code=Lake.class
width=1024
height=768>
<param name=image value="VAIOscape_dawn.jpg">
<param name=overlay value="">
</applet>
</center>
</div>
<div ID="daytime"
STYLE="position:absolute;left:0px;top:0px;
width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet
code=Lake.class
width=1024
height=768>
<param name=image value="VAIOscape_daytime.jpg">
<param name=overlay value="">
</applet>
</center>
</div>
<div ID="sunset"
STYLE="display:none;position:absolute;left:0px;top:0px;
width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet
code=Lake.class
width=1024
height=768>
<param name=image value="VAIOscape_sunset.jpg">
<param name=overlay value="">
</applet>
</center>
</div>
<div ID="midnight"
STYLE="display:none;position:absolute;left:0px;top:0px;
width:1024;height:768;clip:(0,1024,768,0)">
<center>
<applet
code=Lake.class
width=1024
height=768>
<param name=image value="VAIOscape_midnight.jpg">
<param name=overlay value="">
</applet>
</center>
</div>
</BODY>
</HTML>

diades
Tue 18th Jan '05, 6:30am
Hi there,

The use of document all means that it will only operate when viewed via IE, also, document.getElementById("midnight").style.display = '' should be set to "block" or "inline" etc, not an empty string.

ManagerJosh
Thu 20th Jan '05, 5:00am
Hi there,

The use of document all means that it will only operate when viewed via IE, also, document.getElementById("midnight").style.display = '' should be set to "block" or "inline" etc, not an empty string.
Okay, I'm officially lost.. Care to give me the third degree? :)

diades
Thu 20th Jan '05, 6:37am
Hi Josh

document.all is an IE-specific object and is, therefor, not available in other browsers which is the reason that many use it as a test (to check for its existance) to see if the browser in use at the time that the script is running is IE or moz etc., If it the test(if (document.all && disp != 5) {) returns true then the browser is IE and the content of the if s=tatement will be run; if, however, the statement returns false then the browser is other than IE and the script contained therein will never run.
Try removing the (idocument.all &&) from (if (document.all && disp != 5) {) i.e.:
if (disp != 5) {
(and the others)
now the test is just to check on the value of disp. and the browser has nothing to do with it. There is nothing in the script (as far as I can see) that would require a browser-check.

ManagerJosh
Thu 20th Jan '05, 11:26am
You're Brilliant Diades!!! OMGosh!! This took forever to figure out! I'm sooo happy on finally getting this fixed I just want to hug you with big thanks. Sham you live in the UK which makes it physically impossible at the moment

John Campbell
Mon 7th Feb '05, 5:03pm
odd question here. is there a way to do this in a template?

I am trying to find if a user is using anything besides IE do this.... it has to do with the marquee tag

Please and thank you.

diades
Mon 7th Feb '05, 5:13pm
Hi John

As you are talking templates I have to assume that you meen server-side. The answer is that you can glean the information that you want and use it to present browser-specific pages for download but the method is dependent on the server-family (Unix/NT) and the scripting environment or language (asp/php etc)
I am not very well up on this but one of the other guys would prbably have a better idea or, perhaps, if it is php, perhaps post in the php forum:)

John Campbell
Mon 7th Feb '05, 5:16pm
wait isnt there a simple if statement I could use in a template?

like <if conditonal (browser) = IE then do this... if not do the other?

I am sure there is something simple like that no?

diades
Mon 7th Feb '05, 5:21pm
Ha! Sorry, I forgot which forums I was on:D Within VB templates then, yes, it is fully documented in the manual I believe, (as search for is_browser will find it):
<if condition="isset($my_variable) AND is_browser('ie')">
<!-- $my_variable is set and the browser is Internet Explorer -->
</if>

John Campbell
Mon 7th Feb '05, 5:25pm
ohh I hope they dont get made I made my on thread.

so I can copy and paste this code and I am good?
can I use a else statement?
what I want to do is... if its IE
print this. with this fancy unsuported HTML!!!
if it isnt... well just print this:(

if you can put the exact code that would be nice since I have no idea.
LOL
hey I am honest.
(not the code to print of course)

diades
Mon 7th Feb '05, 5:31pm
Hi John

El;se statements are ok to use, the example given is straight from the manual so it will fall over if used as is. It has to be modifeid to suit your needs.

Download the manual from the members area and you will have all the aid/examples that you need on hand.

John Campbell
Mon 7th Feb '05, 5:39pm
Hi John

El;se statements are ok to use, the example given is straight from the manual so it will fall over if used as is. It has to be modifeid to suit your needs.

Download the manual from the members area and you will have all the aid/examples that you need on hand.doesnt work.
I am IE and it doesnt show.
go figure.
I was asking becuase i had a else statement in there but just as is... dont work.
thanks though.

diades
Mon 7th Feb '05, 6:05pm
Did you look up the correct usage in the manual and modify it to your termplate's requirements?

John Campbell
Wed 9th Feb '05, 4:15pm
I got it... I have to drop that $ that was in the example.

<if condition="is_browser('ie')">
is the correct method.