Link to home
Start Free TrialLog in
Avatar of rotemweb
rotemweb

asked on

Cross other XMLHTTP request... Can't cope!

Hi.
I'm using the following function to check if a URL is valid on other websites (i use it to check if an image is available on our supplier's website. It is only called on an 'onclick' event, not at each page load)

The problem is that this works just fine in IE , but Mozilla doesn't seem to accept an outgoing link as a reference.

Is there a not too complicated way to have Mozilla check if an external link is valid or not on a 'onclick' ?

Thanks
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
  /////////////////////////////////////////////////////////////////////////////////////////////////
//Here x.src is the URL of the image
  
  xmlhttp.open("HEAD",x.src,true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   if (xmlhttp.status==200) alert("URL Exists!")
    else if (xmlhttp.status==404) alert("URL doesn't exist!")
     else alert("Status is "+xmlhttp.status)
  }
 }
 xmlhttp.send(null)

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image

For security reasons, browsers are not supposed to let you retrieve data from a different domain using xmlhttp. Firefox is doing what it is supposed to be doing. IE is NOT known as a secure product.
Avatar of rotemweb
rotemweb

ASKER

Ok. So is there a solution to check if an exernal url is valid in AJAX , wih Mozilla?

P-s:I am NOT doing the apology of IE, not the critic of Mozilla. i'm just looking for a cross-browser solution

>>Ok. So is there a solution to check if an exernal url is valid in AJAX , wih Mozilla?
No. At least not directly from the browser. You will need a server-side proxy script to make the image request. What server technology do you have?

>>I am NOT doing the apology of IE
What's this about? Who is asking you to?
>>What's this about? Who is asking you to?
I was refeering to NOT in big caps. Seemed to imply that i am not happy with Firefox. End of topic if it didn't .

>>No.
Ok, no client-side solution then.
Unless a cache refresh is possible to do in javascript before cheking an image load? last solutions didn't seem to indicate it.

>>What server technology do you have?
We have PHP, ASP.




ASKER CERTIFIED SOLUTION
Avatar of rotemweb
rotemweb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial