By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Performing web request

P: n/a
Hi!

Is it possible to perform a webrequest within javascript to find out if a
given url is reachable? (If it isn't then show a placeholder image).
The url can point to both images, video or regular websites.

best regards
Hansen
Sep 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Hansen wrote:
Hi!

Is it possible to perform a webrequest within javascript to find out if a
given url is reachable? (If it isn't then show a placeholder image).
The url can point to both images, video or regular websites.

best regards
Hansen
http://www.galasoft-lb.ch/myjavascript/IsURlActive/

Code:
http://www.galasoft-lb.ch/myjavascri.../check-url.txt

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 4 '06 #2

P: n/a
Sorry for replying my own post, but this calls for more information.

Laurent Bugnion wrote:
Hi,

Hansen wrote:
>Hi!

Is it possible to perform a webrequest within javascript to find out
if a given url is reachable? (If it isn't then show a placeholder image).
The url can point to both images, video or regular websites.

best regards
Hansen

http://www.galasoft-lb.ch/myjavascript/IsURlActive/

Code:
http://www.galasoft-lb.ch/myjavascri.../check-url.txt

HTH,
Laurent
Note: This will work only within the "cross-domain" policy. You cannot
(with the normal permissions) send such a request to another domain.
However, images can send requests to another domain, so this code might
not be sufficient.

Another way would be to use the onerror event handler of the Image object:

<img src="myImage.gif" id="myImage" onerror="showDefaultImage();" />

with

function showDefaultImage()
{
var nImage = document.getElementById( "myImage" );

if ( nImage
&& nImage.src )
{
nImage.src = "iAmSureThatThisImageExists.gif";
}
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.