1

the url is input by end users as string on my page, so may point to any domains.

JavaScript in current page needs to sniff the url, verify whether it's still valid, and return the types as image, or video, or audio, even considering html5 video audio tag and existent flash embed. And No need to wait for the complete file transfer.

Can someone help, from concept? thanks very much.

i'm aware the cross domain problem on ajax. So no idea on basic how-to.

Qishan
  • 165
  • 1
  • 12
  • 3
    It's hard to understand your question. Providing examples would help. Also no one is going to do the work for you here. – Amir Raminfar Mar 15 '12 at 14:08
  • 1
    You can verify if an external url is valid using the HEAD verb: http://stackoverflow.com/questions/333634/http-head-request-in-javascript-ajax – TimDog Mar 15 '12 at 14:10
  • you can the get the url using document.location.href !! now can you give us more details for your other requirements – vireshas Mar 15 '12 at 14:10
  • 1
    Amir, sorry, i'm not ask someone to do labor work for me. but need some concept guide. – Qishan Mar 15 '12 at 14:20

2 Answers2

3

If what you're asking, is:

Given any URL -> lookup given URL using a javascript ajax request, and determine if it is a video/audio/image - then, once detected, use the URL accordingly, then you can do something like this:

jQuery and AJAX response header

However, you'll not be able to make a request using client-side JavaScript to another domain, as it will require a cross-domain request (where your alternatives are JsonP, or weird headers in the response).

You're better off passing the URL to your own server, and performing the logic there (Via some kind of server-side web request) and passing a payload back to the client, with the required information in JSON or something - e.g.

{payload: 'video'}
Community
  • 1
  • 1
Dave Bish
  • 17,987
  • 6
  • 40
  • 60
0

Old question, but I recently wrote a utility that might help you out. It's a CORS-enabled MIME-type checker. See the API doc at lecoq.herokuapp.com

Use it like so: example

David Titarenco
  • 30,718
  • 13
  • 54
  • 108