Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
 
Old December 5th, 2004, 09:39 AM
Authorized User
 
Join Date: Aug 2003
Location: Nicholasville, KY, USA.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old December 5th, 2004, 05:16 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

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%">&nbsp;</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
 
Old December 5th, 2004, 11:08 PM
Authorized User
 
Join Date: Aug 2003
Location: Nicholasville, KY, USA.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Vinod,
I'll give it try!

Best regards,
sabertec2
 
Old December 6th, 2004, 06:30 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can use onerror:
Code:
<img src="http://remoteSource/remoteFolder/myImage.gif" onerror="this.src='file:///C:/localFolder/myImage.gif';">
--

Joe (Microsoft MVP - XML)
 
Old December 6th, 2004, 08:38 AM
Authorized User
 
Join Date: Aug 2003
Location: Nicholasville, KY, USA.
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old December 6th, 2004, 10:39 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Joe,
That's really great.
Simple and nice code :)


Many Many Thanks To You


Cheers :)

vinod




Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternative to Codeplot? pfloyd BOOK: Beginning XML, 4th Ed ISBN: 978-0-470-11487-2 21 June 5th, 2011 03:57 AM
Alternative to BOOKMARKS Shiamak Word VBA 2 October 31st, 2008 04:04 PM
alternative to MemCpy sanjaykabra82 VS.NET 2002/2003 1 September 17th, 2004 12:10 AM
Alternative to onBlur() event ashu_gupta75 Classic ASP Basics 3 April 30th, 2004 09:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.