Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > inserting a new image in a page

Reply
Thread Tools

inserting a new image in a page

 
 
neuneudr@yahoo.fr
Guest
Posts: n/a
 
      03-29-2006
Hi all,

I've been trying JavaScript a little bit. I beginned by changing
an image using a very simple:

document.getElementById(...).src="new image"

Which worked fine.

However this does not work if Firefox is configured with
the "Change images" disabled... Fair enough.

Now I'd like to try something else: not "changing" an image
but inserting a new image, in a page that had no image
previously.

I'd like to do this because the image isn't ready yet when
the user arrives on the page: I want the page to already
render the text, then "insert" an image once the server
is done creating it.

For example, when the user arrives on the page, he sees
the following text:

"Please wait while the server is preparing the data
you want to visualize"

And then after a few seconds the image appears (the
script checks data on the server every second using
XmlHttp requests and once the server warns that he's
ready, I modify the src of an 1x1 image).

As I already said, it works if I change the src of an
image already present on the page (like a 1x1 white
pixel on a white background) but now I'd like
to know if it's possible to insert a whole new image
in a page that had none previously.

Note that I'm not necessarly looking for something that
works even when Firefox's "Change images" is disabled
but simply as to how to insert a new image in a page
instead of changing a 1x1 white pixel.

Thanks in advance,

Driss

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      03-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) said the following on 3/29/2006 8:59 AM:
> Hi all,
>
> I've been trying JavaScript a little bit. I beginned by changing
> an image using a very simple:
>
> document.getElementById(...).src="new image"
>
> Which worked fine.
>
> However this does not work if Firefox is configured with
> the "Change images" disabled... Fair enough.
>
> Now I'd like to try something else: not "changing" an image
> but inserting a new image, in a page that had no image
> previously.


Search the archives for createElement and appendChild:

<script type="text/javascript">
function addImage(URL,divToUse){
oImage = document.createElement('img');
oImage.src=URL;
document.getElementById(divToUse).appendChild(oIma ge);
}
</script>

And then call it as such:

addImage('someImage.jpg','containerToAddItTo');

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
neuneudr@yahoo.fr
Guest
Posts: n/a
 
      03-29-2006
Randy Webb wrote:
> (E-Mail Removed) said the following on 3/29/2006 8:59 AM:
> > Hi all,
> >
> > I've been trying JavaScript a little bit. I beginned by changing
> > an image using a very simple:
> >
> > document.getElementById(...).src="new image"
> >
> > Which worked fine.
> >
> > However this does not work if Firefox is configured with
> > the "Change images" disabled... Fair enough.
> >
> > Now I'd like to try something else: not "changing" an image
> > but inserting a new image, in a page that had no image
> > previously.

>
> Search the archives for createElement and appendChild:
> ...


Thanks a lot for the near-instantaneous answer

It worked perfectly.

And when Firefox's "Change images" is disabled it looks like it's
not possible to "insert" a new image and have it displayed
(I was more or less expecting this).

 
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
Creating a page for inserting new records into a SQL Server 2000 DB newt039@gmail.com ASP .Net 0 01-26-2007 09:33 PM
Upload file and convert image before inserting to db Daniel ASP .Net 1 10-04-2004 06:06 PM
inserting image in title of html page Miguel Angel Javascript 4 09-30-2004 04:53 AM
Rebinding page after image is resized on server not showing new sized image Earl Teigrob ASP .Net 2 02-20-2004 09:44 PM
inserting word document into front page express web page Route 9w Computer Support 7 01-31-2004 04:37 PM



Advertisments