jQuery check external link

后端 未结 3 346
醉酒成梦
醉酒成梦 2020-12-21 15:12

Using Javascript or jQuery, how can I check if an external link is available?

An $.ajax() call is not available as it violates SOP (same problem as her

相关标签:
3条回答
  • 2020-12-21 15:47

    Yes, in browsers that support flash you can use this plugin. It has the same api as native xhr. Further if there is no flash plugin in browsers you still can access the other domain. In some browsers if your target domain response has the following headers there will not be an error.

    Access-Control-Allow-Methods: GET, POST, OPTIONS
    Access-Control-Allow-Credentials: true
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Headers: Content-Type, *
    

    Replace * with appropriate domains.

    All above techniques are applicable only if the second domain is under your control. If not then you have to use a proxy as Jleagle said.

    0 讨论(0)
  • 2020-12-21 15:57

    Do you have access to server side languages? You could use AJAX to call a local file which uses something like PHP to check the external address.

    If you need help with the PHP part, have a look at http://www.catswhocode.com/blog/amazing-things-to-do-with-php-and-curl

    0 讨论(0)
  • 2020-12-21 15:59

    You could use YQL to check if a URL is available via its JSONP interface.

    YQL Console.

    0 讨论(0)
提交回复
热议问题