Hello, I am looking for a piece of Javascript that will check to see if a web page is available at a particular domain - and if the page is available then to redirect to it, however if the page is not available then redirect to an alternative page at a different domain. ...this seems like it should be fairly simple - so if anyone can help I would apreciate it. thanks for looking at my post
You would probably need some backend support for that. It's basically AJAX. Say, you write a page that takes a url as a parameter, and if that url is valid, outputs something like this: <script type="text/javascript"> window.parent.redirectTo("http://valid.url.here.com"); </script> Then in your main page, you define this: function redirectTo(id) { location.href = id; } Then use a hidden iframe to load your backend url, and voila.
Thank you for your response, and you are right the function to redirect to a url works well, however how do I test to see if I should redirect to the url? (if the webserver is offline the user wont see anything) can this be done with javascript? for example if the webpage "http://www.asiatic-lion.org/gallery/chester1.html" can be found by the browser then redirect to it, otherwise redirect to "http://bbc.co.uk"
If you want to do this entirely client-side, without backend support, then XMLHttpRequest object might work for you. Check out this tutorial - http:/developer.apple.com/internet/webcontent/xmlhttpreq.html , or google "xmlhttprequest". You'd need a small subset of its functionality - basically just to check if a page is there or not. There is a 'status' attribute, it might work for you.
Hello SDTEAM I think this article will help you: http://www-128.ibm.com/developerworks/java/library/wa-ajaxintro3/index.html There us a section specifically discussing dealing with "Checking for a URL". Good luck, that sounds like a cool project.
Thank you both for your help, I may not get a chance to sort this out immediately but the links to "http://www-128.ibm.com/developerworks/java/library/wa-ajaxintro3/index.html" and "http:/developer.apple.com/internet/webcontent/xmlhttpreq.html" look very useful. I must admit I had not heard of the "XMLHttpRequest" object, hopefully I can sort out everything over the next few days.... (after the weekend). once again thank you, the help is very much apreciated.