Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > PageFade() with onLoad in <body> Good, with onClick in <a href> Bad??

Reply
Thread Tools

PageFade() with onLoad in <body> Good, with onClick in <a href> Bad??

 
 
Prisoner at War
Guest
Posts: n/a
 
      04-26-2008

Another weekend, another project, another problem....

Why should a perfectly fine function work only half-way through when
called through onClick in an anchor tag??

The text fade-in script below works when called through onLoad in the
<body> tag, but it "hangs" when called through onClick in <a
href="#">, as follows:

<script language="JavaScript1.2">

var hex=240;

function FadePage()
{
if (hex>0)
{
hex-=11;
document.getElementById("text").style.color="rgb(" +hex+","+hex
+","+hex+")";
setTimeout("FadeText()",20);
}
else
{
hex=240;
}
}
</script>


I have a <div> with an id of "text"...again, it all fades in fine when
called through onLoad in the <body> tag but seems to stall at
setTimeout(...) -- maybe it doesn't even get to it at all; the text
just fades in half-way and stays that way, never completing the fade-
in process.

Now why should that be??


TIA!!
 
Reply With Quote
 
 
 
 
Holger Jeromin
Guest
Posts: n/a
 
      04-26-2008
Prisoner at War schrieb am 26.04.2008 18:55:
> Another weekend, another project, another problem....
>
> Why should a perfectly fine function work only half-way through when
> called through onClick in an anchor tag??
>
> The text fade-in script below works when called through onLoad in the
> <body> tag, but it "hangs" when called through onClick in <a
> href="#">, as follows:
>
> <script language="JavaScript1.2">


Just write javascript.

> var hex=240;
>
> function FadePage()
> {
> if (hex>0)
> {
> hex-=11;
> document.getElementById("text").style.color="rgb(" +hex+","+hex
> +","+hex+")";
> setTimeout("FadeText()",20);
> }
> else
> {
> hex=240;
> }
> }
> </script>
>
> I have a <div> with an id of "text"...again, it all fades in fine when
> called through onLoad in the <body> tag but seems to stall at
> setTimeout(...) -- maybe it doesn't even get to it at all; the text


Test this with alerts before and after the style.color rule.

> just fades in half-way and stays that way, never completing the fade-
> in process.
>
> Now why should that be??


Wich Browser showed this problem?

--
Mit freundlichen Grüßen
Holger Jeromin
 
Reply With Quote
 
 
 
 
Prisoner at War
Guest
Posts: n/a
 
      04-26-2008
On Apr 26, 3:27 pm, Holger Jeromin <(E-Mail Removed)> wrote:
>
>
> Just write javascript.


I dunno, I've always like useless little details like that!

> Test this with alerts before and after the style.color rule.


Hmmm, okay, what do you suspect? If an alert() comes up, before or
after, what of it?

> Wich Browser showed this problem?


Well, actually, now that you ask...Opera 9 and IE 7 just ignore the
whole thing and display the page, without any fading-in effect...FF 2
is what gets "stalled" like half-way through....

> --
> Mit freundlichen Grüßen
> Holger Jeromin


 
Reply With Quote
 
Gregor Kofler
Guest
Posts: n/a
 
      04-26-2008
Prisoner at War meinte:
> Another weekend, another project, another problem....
>
> Why should a perfectly fine function work only half-way through when
> called through onClick in an anchor tag??
>
> The text fade-in script below works when called through onLoad in the
> <body> tag, but it "hangs" when called through onClick in <a
> href="#">, as follows:
>
> <script language="JavaScript1.2">


....type="text/javascript".... language is neither needed, nor standard
compliant.

> var hex=240;
>
> function FadePage()
> {
> if (hex>0)
> {
> hex-=11;
> document.getElementById("text").style.color="rgb(" +hex+","+hex
> +","+hex+")";
> setTimeout("FadeText()",20);


What or where is "FadeText()"? Or did you mean FadePage()?

Gregor


--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
 
Reply With Quote
 
Holger Jeromin
Guest
Posts: n/a
 
      04-27-2008
Prisoner at War schrieb am 27.04.2008 00:43:
> On Apr 26, 3:27 pm, Holger Jeromin <(E-Mail Removed)> wrote:
>>> <script language="JavaScript1.2">

>> Just write javascript.

> I dunno, I've always like useless little details like that!


I said, that you should not specify the javascript version in this tag.
<script language="JavaScript"> is better.

>> Test this with alerts before and after the style.color rule.

> Hmmm, okay, what do you suspect? If an alert() comes up, before or
> after, what of it?


you said, that you have no idea, if the browser reaches this point of
your code. You can test this with a few alerts...

--
Mit freundlichen Grüßen
Holger Jeromin
 
Reply With Quote
 
Gregor Kofler
Guest
Posts: n/a
 
      04-28-2008
Holger Jeromin meinte:

> I said, that you should not specify the javascript version in this tag.
> <script language="JavaScript"> is better.


Why? This attribute is deprecated and useless (unless you are writing
for some browsers of ancient times). However, if you want valid markup
you have to provide a type attribute. [1]

Gregor


[1] <http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.2.1>



--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
 
Reply With Quote
 
Prisoner at War
Guest
Posts: n/a
 
      04-28-2008
On Apr 26, 6:44 pm, Gregor Kofler <(E-Mail Removed)> wrote:
> Prisoner at War meinte:
>
> > Another weekend, another project, another problem....

>
> > Why should a perfectly fine function work only half-way through when
> > called through onClick in an anchor tag??

>
> > The text fade-in script below works when called through onLoad in the
> > <body> tag, but it "hangs" when called through onClick in <a
> > href="#">, as follows:

>
> > <script language="JavaScript1.2">

>
> ...type="text/javascript".... language is neither needed, nor standard
> compliant.


I see that now! Goodness, why all this messing around all the time
with depreciating tags and attributes...reminds me of how Microsoft
moves things around in MS Word, etc.

> > var hex=240;

>
> > function FadePage()
> > {
> > if (hex>0)
> > {
> > hex-=11;
> > document.getElementById("text").style.color="rgb(" +hex+","+hex
> > +","+hex+")";
> > setTimeout("FadeText()",20);

>
> What or where is "FadeText()"? Or did you mean FadePage()?


Yes, you are correct: I meant "FadePage ()" -- "FadeText()" is just
another name; sorry for the confusion!

> <SNIP>

 
Reply With Quote
 
Prisoner at War
Guest
Posts: n/a
 
      04-28-2008
On Apr 27, 4:23 pm, Holger Jeromin <(E-Mail Removed)> wrote:
>
>
> I said, that you should not specify the javascript version in this tag.
> <script language="JavaScript"> is better.


I know, I know: W3C standards compliance. I wonder why they keep
changing these standards, though. Now "type" is the preferred
attribute -- and instead of "text/JavaScript" they will want
"application/JavaScript" next!

> you said, that you have no idea, if the browser reaches this point of
> your code. You can test this with a few alerts...


Yes, but then what...I mean, what if it never reaches that point in
the code, and what if it does? What would it mean -- why would
reaching or not reaching that point cause the effect?

I'm trying to figure out what the FF2 browser is "thinking" WRT that
code...IE7 and Opera 9 seem to totally ignore it. Is the code itself
wrong? Why does it work onLoad in the <body> tag but not onClick in
an <a href> anchor tag??

> --
> Mit freundlichen Grüßen
> Holger Jeromin


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-29-2008
Gregor Kofler wrote:
> Prisoner at War meinte:
>> <script language="JavaScript1.2">

>
> ...type="text/javascript".... language is neither needed,


Correct.

> nor standard compliant.


Wrogn. The `language' attribute of the `script' element is specified in the
Web standards HTML 4.01 Transitional [1], and XHTML 1.0 Transitional [2].

It is not specified in the Web standard HTML 3.2 as the `script' element has
no attributes there.[3] It is not specified in the Web standards HTML 4.01
Strict [4], and XHTML 1.0 Strict [5], because it is *deprecated* for obvious
reasons.[6] (JFTR, the `script' element is not specified in ISO/IEC
15445:200(E) at all.[6])


PointedEars
___________
[1] http://www.w3.org/TR/1999/REC-html40.../loosedtd.html
[2]
http://www.w3.org/TR/2002/REC-xhtml1...0-Transitional
[3] http://www.w3.org/TR/REC-html32
[4] http://www.w3.org/TR/1999/REC-html40...strictdtd.html
[5]
http://www.w3.org/TR/2002/REC-xhtml1...TML-1.0-Strict
[6]
http://www.w3.org/TR/1999/REC-html40....html#h-18.2.1
[7] https://www.cs.tcd.ie/15445/TC1.html
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
onload -->* no onload marco Javascript 7 06-24-2006 08:39 PM
Why doesn't frameset onload event get called when each of the frames has an onload? adnanx82@gmail.com Javascript 5 05-15-2005 01:58 PM
base.OnLoad called, OnLoad not executed Fabio R. ASP .Net 0 03-25-2005 01:21 PM
window.onload and body.onload differences David Otton Javascript 2 11-04-2004 04:34 PM
document.onclick=doIt() same as document.onclick=doIt ? bob Javascript 3 08-21-2003 12:14 PM



Advertisments