Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > IE no doing "onload" function?

Reply
Thread Tools

IE no doing "onload" function?

 
 
fred.haab@gmail.com
Guest
Posts: n/a
 
      05-25-2006
Not having server side scripting, I've been doing this for "last
modified" tags on my pages:

<div class="modified">
<script type="Text/JavaScript">
<!--
document.write("This page was last modified: " +
document.lastModified);
-->
</script>
</div>

It suffices, but supposedly it's better to separate content and the
code.

So in a separate js file I did this:

window.onload = last_modified;

function last_modifed()
{
var obj = document.getElementById("modified");
obj.innerHTML = "This page was last modified: " +
document.lastModified;
}

With this html in my documents:

<div id="modified" class="modified">&nbsp;</div>

It does't work in my IE (6), but works fine in Firefox. Any
suggestions?

 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      05-25-2006

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> So in a separate js file I did this:
>
> window.onload = last_modified;
>
> function last_modifed()
> {
> var obj = document.getElementById("modified");
> obj.innerHTML = "This page was last modified: " +
> document.lastModified;
> }
>
> With this html in my documents:
>
> <div id="modified" class="modified">&nbsp;</div>
>
> It does't work in my IE (6), but works fine in Firefox. Any
> suggestions?


Put
window.onload = last_modified;

after the function declaration (at the end of your script).

 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      05-25-2006
VK wrote:
> (E-Mail Removed) wrote:

<snip>
>> It does't work in my IE (6), but works fine in
>> Firefox. Any suggestions?

>
> Put
> window.onload = last_modified;
>
> after the function declaration (at the end of your
> script).


It is not even a couple of days since were beaten into accepting that
variable declarations are acted upon during variable instantiation,
prior to the execution of any actual code for the execution context. You
even claimed to have read the specification. Yet you didn't see, or
didn't understand, that the same is true of function declarations.

The location of an assignment of a reference to a declared global
function in the global execution context does not matter because the
function will have been created prior to the execution of any actual
code.

If you are not capable of actually comprehending javascript yourself you
really should not bother other people with the nonsense that you mistake
for an understanding of javascript.

Richard.


 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      05-25-2006
function last_modifed()
but
window.onload = last_modified;

you have a typo in modified.

 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      05-25-2006

Richard Cornford wrote:
> It is not even a couple of days since were beaten into accepting that
> variable declarations are acted upon during variable instantiation,
> prior to the execution of any actual code for the execution context. You
> even claimed to have read the specification. Yet you didn't see, or
> didn't understand, that the same is true of function declarations.


I found the actual error - see another post. For the mater of variable
instantiation it is just not my cup of tea I'm affraid. I mean of
course I understood the trick (so stupid I'm not but I simply don't
like it. So I will continue to declare all used variable explicetly in
my code: you can call it instead then "list all used variable in
advance". And for functions I will put references and calls only after
function declarations. Maybe it doesn't have any sense - but I just
used to do so and it is useful for the consistency with other
languages. Anyone is welcome though to act otherwise.

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      05-25-2006
VK wrote:
> Richard Cornford wrote:
>>> (E-Mail Removed) wrote:
>>>> It does't work in my IE (6), but works fine in
>>>> Firefox. Any suggestions?
>>>
>>> Put
>>> window.onload = last_modified;
>>>
>>> after the function declaration (at the end of your
>>> script).

<snip>
>> You even claimed to have read the specification. Yet you
>> didn't see, or didn't understand, that the same is true
>> of function declarations.

>
> I found the actual error - see another post.


Does the error you pointed out actually explain the symptoms described?
Will the code with that error work in Firefox but not work in IE6? If
the symptoms are real then the code posted cannot be producing them, so
you may have just pointed out a typo in the posted code.

> For the mater
> of variable instantiation it is just not my cup of tea I'm
> affraid. I mean of course I understood the trick (so stupid
> I'm not but I simply don't like it. So I will continue to
> declare all used variable explicetly in my code: ...

<snip>

You just don't get it, do you? In response to the posted question you
have proposed an action that you should have known would make no
practical difference at all. It doesn't matter that 'best practice' may
be to declare variables and functions before other code. You were not
recommending those changes as a gesture towards beast practice, you were
implying that it might make a difference that might resolve the issue.
Implying that you were not aware that it should not be expected to make
any difference at all.

All your response to my comments represents is yet another lame attempt
to excuse your evident incompetence.

Richard.


 
Reply With Quote
 
fred.haab@gmail.com
Guest
Posts: n/a
 
      05-26-2006
As Richard surmised, it was a typo in cutting and pasting. Correctly
named, it works in Firefox, but not IE.

 
Reply With Quote
 
fred.haab@gmail.com
Guest
Posts: n/a
 
      05-26-2006
Yes, I would like to follow "best practices" so that my web pages
degrade as gracefully as possible, so given what you wrote, do you have
any suggestions about why this may not work in IE?

The first example, with the inline script, works. The second does not
(in IE).

Thanks,
Fred

 
Reply With Quote
 
fred.haab@gmail.com
Guest
Posts: n/a
 
      05-26-2006
I've discovered that IE simply doesn't like my .js file at all, even
with only what you see in my first post. If I remove the <script> tag
that loads the .js file, IE will at least display (but no script). If
I leave the script tag in, IE won't display ANYTHING, not even static
content right in the HTML file.

Maybe the tag is in the wrong place? I have it in <head> element.

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      05-26-2006
(E-Mail Removed) wrote:
> I've discovered that IE simply doesn't like my .js file at all,
> even with only what you see in my first post. If I remove the
> <script> tag that loads the .js file, IE will at least display
> (but no script). If I leave the script tag in, IE won't display
> ANYTHING, not even static content right in the HTML file.
>
> Maybe the tag is in the wrong place? I have it in <head> element.


A SCRIPT element is allowed to be the direct child of a HEAD element in
HTML documents.

Maybe your SCRIPT element is wrong itself. If you attempted to apply the
illusion of XHTML to an HTML document with a SCRIPT element such as:-

<script src="removteFile.js" type="text/javascript" />

- some browsers may be capable of error correcting that back into an
HTML script element, while others (and certainly IE) would not be able
to cope with that level of error correction and so see that as only the
opening SCRIPT tag, making everything that followed it into the contents
of the script elements. In the second case the result likely would be an
empty browser window.

Richard.


 
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
recommendation doing co-simulation between c/c++ with vhdl Carson VHDL 0 10-05-2005 07:40 PM
What is VS Doing to my Code??? downs.matt@gmail.com ASP .Net 1 09-02-2005 11:38 AM
Why is Mozilla doing this ... and how to fix it Joe S. Firefox 7 06-07-2005 04:12 AM
VB6/VB.Net Programming Question - what am i doing wrong? Salisha Khan ASP .Net 1 08-01-2003 01:55 PM
What am I doing wrong? Keith R. Williams VHDL 4 07-15-2003 03:08 AM



Advertisments