473,387 Members | 3,821 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,387 software developers and data experts.

inserting a new image in a page

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

Mar 29 '06 #1
2 1773
ne******@yahoo.fr 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/
Mar 29 '06 #2
Randy Webb wrote:
ne******@yahoo.fr 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).

Mar 29 '06 #3

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

Similar topics

1
by: Mat | last post by:
Hi, I have a system that uploads images as BLOBs in a database. I also have a function that I use to resize uploaded images before saving as files. I would like to combine these two by resising...
5
by: Miguel Angel | last post by:
Hi, I would like to insert an image into a html page title. I have been looking for information on how to do it, but haven't found any, thus here I am. I may be in the wrong place, but I...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
1
by: developers | last post by:
Hello Every One , I need Help in inserting the user image in my data base. but unfortunatly I don't know how.I'm using asp with sql server. I tried to insert the image and i geuss it worked.for...
1
by: Mike Fellows | last post by:
I have some images stored locally that i retrieve and insert into a word document that is programatically created im using the following code If File.Exists("C:\Pic2.jpg") Then...
3
by: lmeeson | last post by:
hi guys, I am totally new to coding so please bare with me. I have a file upload field in a form on a PHP page for users to upload pictures, i also have the following fields in my MySQL database ...
4
by: ghjk | last post by:
I wan to add some data using php page to mysql db. But I got the error saying "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.