SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast sussmal's Avatar
    Join Date
    Nov 2003
    Location
    Los Angeles
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to page redirect if server is down?

    Hopefully I can make this clear for any of you to help with this.

    I am running on my local pc a local html file. I have this local html file displaying news feeds from various sources. In addition, the local file is pulling images and contect from external domains.

    Is there a javascript, or html code that will allow my local html file to check to see if the external domains are active. If they happen to go down, I end up with blotchs on my local html site due to the images or text not appearing.

    My goal is for the local html file to check to see if the external domains are alive - (perhaps by looking for a small gif). If the external domain is down, the script of code will redirect my local webpage to an existing html webpage that is stored locally. The existing html webpage will bring up default content.

    Does anyone know how to code this? If so, would you be so kind as to paste your code so I can use it?

    Thank you!

  2. #2
    SitePoint Wizard silver trophy KLB's Avatar
    Join Date
    Nov 2003
    Location
    Maine USA
    Posts
    3,781
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You use JavaScript to request the image and then test to see if the image was delivered properly it it was it would be displayed on your site. If it wasn't, the alternative image would be requested and displayed. You could do something like this (note: not exact code you will have to play with it to make it work):
    Code:
    <script language="JavaScript" type="text/javascript" >
    loadIMG = new Image();
    loadIMG.src = "http://someserver.com/graphic.gif";
    if(!loadIMG){document.getElementById('idIMG').src='http://someotherserver.com/alternate/graphic.gif';}
    </script>
    <img src="http://someserver.com/graphic.gif" id="idIMG">
    Again you would need to flush this out.
    Ken Barbalace: EnvironmentalChemistry.com (Blog, Careers)
    InternetSAR.org
    Volunteers Assist Search and Rescue via Internet
    My Firefox Theme: Classic Compact
    Based onFirefox's default theme but uses much less window space

  3. #3
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think it would be better if the image is not loaded in the <img> tag. It should
    be done through javascript so that it displays whichever image is available.
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •