sonnystarks said:
I'm sorry but your answer is a clear as mud... not your fault, I'm sure
but mine. I am still not getting it.
Let's use an example please. The course I am taking says to put my <h1>
tags within the javascript syntax. Now, if Johnny Doe goes to my
website in this example, what difference will he see when he looks at
<h1>This is a headline</h1> in ordinary HTML and if it is in the
Javascript syntax?
If he doesn't have javascript enabled or available, he won't see the
heading
I don't grasp the "Only before the page has finished
loading. If the page has finished loading, then document.write will
clear the current page and replace it
with whatever you document.write" concept.
It means if you wait until the page has finished loading, then
document.write your heading, it will be the only thing on the page.
I have looked at examples of javascript code and understand what it
does in the final appearance, " as in a clock or calendar, > Dynamic
content based on parameters." but don't understand how it is an
advantage in ordinary <a href> or <h?> tags?
In that particular example, it means you can easily write the date to
the page based on the users system clock rather than your server clock -
document.write is not the only way to do that.
As a quick 'n dirty example:
<title>foo</title>
<script type="text/javascript">
function getDate(){
var now = new Date();
return now.getFullYear() + '.'
+ (now.getMonth()+1) + '.'
+ now.getDate();
}
</script>
<!-- document.write -->
<h1><script type="text/javascript">
document.write(getDate());
</script></h1>
<!-- DOM equivalent -->
<h1 id="h1"></h1><script type="text/javascript">
var tn = document.createTextNode(getDate());
document.getElementById('h1').appendChild(tn);
Is it an example of "speed" while the page is loading? Is this what you
are trying to tell me? Is it something to do with the webpage refresh
rate?
None of the above. document.write is a relic of very early JavaScript,
it is not part of the W3C DOM. It belongs to "DOM 0", which is the
collection of functionality that was common between IE and Netscape
about the time the W3C published their DOM 1. Other browsers also
implement DOM 0 stuff, document.write is likely supported by every
single browser that also supports scripting.