Javascript:如何检查url的存在?

时间:2022-08-23 10:19:53

I need to check the whether an external url like http://www.example.com exists or not using javascript or ajax.

我需要使用javascript或ajax检查是否存在http://www.example.com之类的外部URL。

Thanks in advance..

提前致谢..

1 个解决方案

#1


3  

You can load it into a hidden iframe and see if you get content. You can't use "ajax" (e.g., an XMLHttpRequest call) for it, because you'll run into Same Origin Policy restrictions.

您可以将其加载到隐藏的iframe中,看看是否获得了内容。您不能使用“ajax”(例如,XMLHttpRequest调用),因为您将遇到Same Origin Policy限制。

#1


3  

You can load it into a hidden iframe and see if you get content. You can't use "ajax" (e.g., an XMLHttpRequest call) for it, because you'll run into Same Origin Policy restrictions.

您可以将其加载到隐藏的iframe中,看看是否获得了内容。您不能使用“ajax”(例如,XMLHttpRequest调用),因为您将遇到Same Origin Policy限制。