 |
Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

December 5th, 2004, 09:39 AM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Image Alternative
Objective:
Have a web based eBook in which I want to include an image that is located on a separate web server. This is easy enough to do.
Problem:
As an eBook is typically open and viewed on the client's computer, there is no guarantee that they will have access to the internet, allowing the image to load. If it is not possible to access and load the desired image, I want to redirect the image source to a file local to the eBook.
What means, methods, properties can I use to determine a) whether an internet connection exists and/or b) whether the desired image file is or can be loaded?
Any suggestions?
Best regards,
sabertec2
|

December 5th, 2004, 05:16 PM
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hii TSEROOGY,
Yes You can do this ,
<table>
</tr>
<tr><td><a href="http://www.wrox.com/go/home">
<img id="id1" src="testing.gif" width="38" height="76" border="0" ></a></td>
<td width="100%"> </td>
<td>test</td>
</tr>
</table>
<script>
function clickit()
{
obj=document.getElementById("id1")
if(!(obj.complete))
{
//create a tempobject
tempimg=document.createElement("img")
tempimg.src="http://anyothersite1919.com/foldername/imagename.gif"
//tempimg.src can be either to local folder or any other sites
//tmpimg.src="text.gif" i.e local files
obj.src="http://anyothersite1919.com/foldername/imagename.gif" //or local file name
obj.height=tempimg.height
obj.width=tempimg.width
}
}
</script>
Now we can call this function at the end,when page is loaded successfully.
obj.complete is used to check whether image is successfully loaded or not
I think ,In order to swap images ,all the images should be loaded and
every <img> or <inut type=image> must have an "Id",because
document.getElementsByName("imgname")
will take care about all the images named with "imgname"
so ,i prefer getElementById :)
I can swap images every time when page is loading,but it will take more time ,isn't it
I am new to javascript,Looking for suggestions to improve page processing
Thanks in Advance
Cheers :)
vinod
|

December 5th, 2004, 11:08 PM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks, Vinod,
I'll give it try!
Best regards,
sabertec2
|

December 6th, 2004, 06:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You can use onerror:
Code:
<img src="http://remoteSource/remoteFolder/myImage.gif" onerror="this.src='file:///C:/localFolder/myImage.gif';">
--
Joe ( Microsoft MVP - XML)
|

December 6th, 2004, 08:38 AM
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Joe,
Thank you.
I can't believe it's that simple? Just the way I like it.
I'll give this a swing, too.
Best regards,
sabertec2
|

December 6th, 2004, 10:39 AM
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Joe,
That's really great.
Simple and nice code :)
Many Many Thanks To You
Cheers :)
vinod
|
|
 |