Click to See Complete Forum and Search --> : Redirect if original website is not available


raul
05-20-2003, 06:36 PM
How can I redirect users to an alternate website if original link is not available or times out.
I want my library users to normally access a website, but given flaky connection issues, there are times when such site is not available, thus at that point I would like my users to access an alternate page that is in a separate network.

Thanks! Raul.

brendandonhue
05-20-2003, 06:40 PM
You would have to load the page into frames or an iframe so you can say, wait 5 seconds, and check if the URL in the other frame/iframe is what its supposed to be, if not, change the URL of it to the other site.

havik
05-20-2003, 08:46 PM
This would have to be the job of a server side language. Once the link has been clicked, the page is gone and the new one is accessed and displayed on your screen. Should the page time out, the link you clicked on can't acknowledge this since it no longer exists on your browser.

Unless you call your links within an element of the current page, like an iframe for example, then I would say that this can't be done with javascript alone.

Havik

raul
05-21-2003, 10:50 AM
Frames are OK by me. Any ideas of how the script would look like?


PS. I'm not sure I know what an iFrame is...

brendandonhue
05-21-2003, 02:42 PM
iFrame = inline frame. Its a frame, only its inside the page.
Here is how the script would be. Lets say the page is loaded into a frame called "main" and the script will go in a frame named "top".

<script language="javascript">
function check()
{
var desired_url = "http://mysite.com/index.html";
var mainURL = "document.main.location.href";
alternate_url = "http://othersite.com/index.html";
if (mainURL != desired_url)
{document.main.location.href = alternate_url}
else {}
}
setTimeout('check();', 5000);
window.clearTimeout
</script>

muppets
10-19-2003, 06:16 PM
Close brendandonhue

But here is the working script based on your original for the top frame.

<script language="javascript">
function check()
{
var desired_URL = "www.desired-url.com/file.htm";
var mainURL = "parent.frames.main.location.href";
var alternate_url = "www.alternate-url.com/alternatefile.htm";
if (parent.frames.main.location.href != desired_url)
{parent.frames.main.location.href = alternate_url}
else {}
}

setTimeout('check();', 100);

</script>

Altering the timeout length depending on site load times.

Alternatively I created a script that checks for site title that could be useful (well was in my case).

</script>
<script language="javascript">
function check()
{
var desired_title = "Desired Pages' Title";
var alternate_url = "Alternate URL";
if (parent.frames.main.document.title != desired_title)
{parent.frames.main.location.href = alternate_url}
else {}
}

check();

</script>

This came in handy because I didn't know where the page was going to be located when installed on the hard drive of a computer. However the page title was unaltered.