Need to test for URL access and if not available go to a different URL

trower
trower used Ask the Experts™
on
Hi
I am trying to test if a URL is available and if it isn't then I would like to send the user to a different URL. I have tried a 'try' statement but it doesn't work properly because as well as doing the action I want it also 'actions' the 'try' statement.
Can you use a window.open in the 'try' section ? or even a window.location.href in the try statement ?
Thanks
Paul


// use a try block to ascertain if we can access the dot int site
	var canAccessDotInt = "yes";
	try
	{
	window.open("http://learningpoint.mottmac.group.intt");
//	window.location.href = "http://learningpoint.mottmac.group.intt";
	}
	catch(error)
	{
	canAccessDotInt = "no";
	}
// access dot int if we can else go to dot com
	if (canAccessDotInt == "yes")
	{
	window.open("http://learningpoint.mottmac.group.int");
	}
	else
	{
	window.open("http://www.learningpoint.mottmac.com");
	}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Refer this link. it will be useful to you,
http://www.webdeveloper.com/forum/showthread.php?t=165298

Author

Commented:
thanks for that - how about something that is cross domain though ?
Commented:
I have fixed this myself now so I will close the call.

Thanks
Paul
function httpRequest( url )
{
	var httpObj = new ActiveXObject('Microsoft.XMLHTTP');
	httpObj.open( "GET", url, false );
	httpObj.send();
	var st = httpObj.status;
	var response;
		if( st >= 200 && st < 300 )
		{
		response = httpObj.responseText;
		}
	var retval = new Object;
	retval.status = st;
	retval.response = response;
	return retval;
}
and this on the onclick of the button
// use a try block to ascertain if we can access the dot int site
var canAccessDotInt = "yes";
	try
	{
	var answer = httpRequest( "http://xyzmimi.mottmac.com" );
	alert("no error");
	}
	catch (e )
	{
	alert("erroring");
	canAccessDotInt = "no";
	}
// access dot int if we can else go to dot com
        if (canAccessDotInt == "yes")
        {
        window.open("http://learningpoint.mottmac.group.int");
        }
        else
        {
        window.open("http://www.learningpoint.mottmac.com");
        }

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial