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

document.write() is replacing image

Hello all;

I have a web page that displays a blank gif for about 2 seconds, then
displays an animated gif image, then, after the animation plays, I want to
display a link so the user can click on it and go to another page. I am
fairly new to javascript and came up with the following code:

-----------------------
<p align="center"><img src="images/nil.gif" align="middle" width="375"
height="300" name="blank_image"></p>
<script language="javascript">
function create_link() {
// document.write('<p align="center"><a href="index2.htm">ENTER</a></p>');
document.write('<p align="center"><a href="index2.htm">ENTER</' +
'a></p>');
}
</script>
<script language="javascript">
ccs_img = new Image(76, 21);
ccs_img.src = "images/ccs_logo_animated_rotate.gif";
setTimeout("document['blank_image'].src = ccs_img.src", 2000);
setTimeout("create_link()", 7100);
</script>
-----------------------

The problem is that when the "create_link" script executes it replaces the
existing image and only the link appears (I would like the link to appear
centered under the image). I've searched google for more info and have been
experimenting with document.write and setTimeout. I am confused by the
results I get. Hopefully someone can explain what's happening and why, or
what I am doing incorrectly.

If I put the following in a page:

<script>
document.write("123");
document.write("456");
</script>

I get: 123456 -- the output from both document.write commands is displayed.
If I put the following in a page:

<script>
document.write("123");
document.write("456");
setTimeout('document.write("ABC")', 1000);
</script>

I get: 123456, then after 1 second this is replaced by ABC -- I would expect
123456ABC
If I put the following in a page:

<script>
setTimeout('document.write("ABC")', 1000);
setTimeout('document.write("456")', 2000);
</script>

I get: ABC and the 456 never appears!!

I am confused!!

As I am still in the initial learning curve for javascript, I'm not sure
what to look for or where to look.

1) Can I do what I want but just don't know how?
2) Is there a way to put the link on the page via HTML and keep it
disabled/invisible until the animation plays?
3) Does anyone have any other ideas?

TIA.

Charles...
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.682 / Virus Database: 444 - Release Date: 5/11/04
Jul 23 '05 #1
4 2947
Charles Crume wrote:

<snip>

If I put the following in a page:

<script>
setTimeout('document.write("ABC")', 1000);
setTimeout('document.write("456")', 2000);
</script>

I get: ABC and the 456 never appears!!

I am confused!!


Once the document is loaded, any subsequent "document.write()"
statements will overwrite all content on the page.

Look into using "document.getElementById()" collection

<p id="goobers"></p>
Jul 23 '05 #2
Hi Mick;

"Mick White" <mw******@BOGUSrochester.rr.com> wrote in message
news:R6********************@twister.nyroc.rr.com.. .
Once the document is loaded, any subsequent "document.write()"
statements will overwrite all content on the page.
Look into using "document.getElementById()" collection


[snip]

Thanks for the reply. I am checking into getElementById(). However, I still
do not understand why the document.write() in the 2nd setTimeout does not
get displayed. What am I not understanding here??

Charles...

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.682 / Virus Database: 444 - Release Date: 5/11/04
Jul 23 '05 #3
In article <jC**************@fe2.columbus.rr.com>,
"Charles Crume" <cc@charlescrumesoftware.com> wrote:
<script>
document.write("123");
document.write("456");
setTimeout('document.write("ABC")', 1000);
</script>

I get: 123456, then after 1 second this is replaced by ABC -- I would expect
123456ABC


It may be that setTimeout is a function that waits for one second then
the line of code after it gets run. In reality, setTimeout schedules a
function, write.document, to be run one second from from the call to to
setTimeout. The statement following the setTimeout is run next. Since
it is a </script> the rest of the document is processed.

The run order of the following is:
{1}<script>
{2}document.write("123");
{3}document.write("456");
{4}setTimeout('{in one second}document.write("ABC")', 1000);
{5}</script>
{6}<p>Is inserted in the document before the document.write
gets run.</p>

Were number and words in { } are the run sequence.

Robert
Jul 23 '05 #4
Charles Crume wrote:
"Mick White" wrote :
Once the document is loaded, any subsequent "document.write()"
statements will overwrite all content on the page.
Look into using "document.getElementById()" collection [snip]
Thanks for the reply. I am checking into getElementById().


I am not sure what - getElementById - has got to do with the problem, -
innerHTML - or the nodeValue - and - date - properties of text Nodes
seems more related, though getting a reference to some element in which
to modify the contents would probably involve - getElementById - at some
point.
However, I
still do not understand why the document.write() in the 2nd
setTimeout does not get displayed. What am I not understanding here??

<snip>

The second timeout never happens because the first - documjent.write -
*replaces* the current document, including all accompanying scripts and
scheduled timeouts.

(Incidentally, if you actually wanted to use - document.write - to
replace the current document (or to write into a pop-up or IFRAME's
document) then it is necessary to also call - document.close - so that
the browser knows you have finished writing. It also becomes symmetrical
to call - document.open - prior to starting to write to a closed
document, though all implementations seem to implicitly call it when the
first - document.write - is executed.)

Richard.
Jul 23 '05 #5

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

Similar topics

2
by: Monte Gardner | last post by:
At my company, we have a javascript function that uses document.write() calls to create an INPUT tag with type set to "image". The image that it is downloading comes from a dynamic image server,...
0
by: Robin Tucker | last post by:
At the moment I have place-holders in my Word document (before you say it, yes I've posted this query in the VBA newsgroups but they are a little slow - in fact reply was non-existent!). I'm...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
2
by: ethandbrown | last post by:
Hi All-- I'm a bit stymied here. I need to display arbitrary HTML obtained through AJAX. The problem is when a <script> block is encountered one can't use innerHTML to set the content, because...
1
by: extremerep | last post by:
I am trying to have "window.document.images.src=''+cards1+'.gif'" work in a loop just as "document.write(<img src="'+cards+'">); does, but it does not seem to be within Javascript's ability. ...
1
by: pseudomagazine | last post by:
Little problem: Using the document.write() function and an enormous string, I have managed to create self-generated pages with functions calling code located in external scripts. The code that...
6
by: Rob | last post by:
Hello, I'm sure this has come up before. I have need for a collection of all elements/objects in an HTML document that have any kind of an attribute (HTML or CSS) that is making use of a URL to...
1
by: Schannah | last post by:
I'm trying to make a layout in which the titles of articles (and possibly articles themselves, although they're written in an editor that breaks lines so I can't as yet include the article variable...
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.