Redirect IFRAME - how to avoid "404 error - Page not fo

Questions? Suggestions? Need help? Talk about anything related to Yawcam...
Post Reply
Thomas Acid
Posts: 64
Joined: Sat Dec 27, 2008 7:01 pm

Redirect IFRAME - how to avoid "404 error - Page not fo

Post by Thomas Acid »

A question for web designers:

Scenario: I'm using IFRAME in my home page.
If I shutdown Yawcam, the IFRAME will display a blank page "404 ERROR-PAGE NOT FOUND".
I want to redirect only the IFRAME content(yawcam page) to another content located in my webhost(an offline image).

I can do this using the script below, but it's PHP and I'm looking for something that's work in HTML pages. I can convert my page from HTML to PHP, but this will broken my links to this page.

Can javascript handle IFRAME redirections?

Code for PHP 5.3 pages (maybe works in PHP 5.2):

Code: Select all

<?php
ini_set('default_socket_timeout', 10);

$checkOnline = @file_get_contents("http://public_ip_adress:8081/just_dummy_small_file_located_in_stream_folder.txt");

if ($checkOnline) {

echo '<iframe src="http://public_ip_adress:8081" frameborder="no" scrolling="no" border="0" marginwidth="0" marginheight="0" hspace="0" style="width: 640px; height: 480px;"></iframe>';
}

else {

echo '<img src="offline.jpg">';
}

?>
malun
Site Admin
Posts: 1590
Joined: Sun Jan 04, 2004 1:29 pm

Post by malun »

This can be handled with javascript. Perhaps not the most elegant way to solve this, but it works.

Code: Select all

<html>

<p id="iframe" align="center">
<iframe src='http://localhost:8081/index.html' style='border:none' frameborder='0' width="800" height="600" onError="location.href='offline.jpg'"></iframe>
</p>

<img src="http://localhost:8081/onlinetestimg.jpg" width="1" height="1" style="visibility:hidden" onError="document.getElementById('iframe').innerHTML = '<img src=\'offline.jpg\'>'">

</html>
This requires that you create an image onlinetestimg.jpg on 1x1 pixels and place in the stream directory. Also that you upload offline.jpg to your own web server.

/malun
Thomas Acid
Posts: 64
Joined: Sat Dec 27, 2008 7:01 pm

It's works

Post by Thomas Acid »

malun wrote:... but it works...
Good enough for me! Thank You !!
bben95
Moderator
Posts: 39
Joined: Thu Feb 04, 2010 2:40 pm

Post by bben95 »

malun wrote:This can be handled with javascript. Perhaps not the most elegant way to solve this, but it works.

Code: Select all

<html>

<p id="iframe" align="center">
<iframe src='http://localhost:8081/index.html' style='border:none' frameborder='0' width="800" height="600" onError="location.href='offline.jpg'"></iframe>
</p>

<img src="http://localhost:8081/onlinetestimg.jpg" width="1" height="1" style="visibility:hidden" onError="document.getElementById('iframe').innerHTML = '<img src=\'offline.jpg\'>'">

</html>
This requires that you create an image onlinetestimg.jpg on 1x1 pixels and place in the stream directory. Also that you upload offline.jpg to your own web server.

/malun
This is great! I've been looking for something like this ever since I started running a webcam. I've implemented it on my webcam now: http://benellis.info/
Although I have edited it a bit. Take a look at the source to see if you want a http://benellis.info/webcam
fantom
Posts: 1
Joined: Thu May 19, 2011 10:41 am

Post by fantom »

how do I do this if I am not using frames?
Post Reply