0

Can I evaluate the status of a URL on a remote server with JavaScript? Is it considered a cross-domain reference even if I don't get the actual contents of a document?

If it's not possible through plain JavaScript, could I perhaps load the document in an iframe?

What I would like to do is to check if the HTTP status code is 200 and if the Content-Type is text/xml, to make sure the URL a user entered is valid.

I'm using YUI btw.

2 Answers 2

4

Can I evaluate the status of a URL on a remote server with JavaScript?

Not in a standard browser security context (which I'll assume unless you say otherwise as it covers almost all use cases).

Is it considered a cross-domain reference even if I don't get the actual contents of a document?

Yes.

If it's not possible through plain JavaScript, could I perhaps load the document in an iframe?

No, and even if you could you wouldn't have access to the HTTP headers.

Sign up to request clarification or add additional context in comments.

Comments

2

You're right in your assumptions that any XMLHTTPRequest to a non-local path is considered cross-domain, regardless of its nature.

That's not to say it can't be done. For example, you could route your request through a local server-side script (ie. PHP/Python/Ruby et al) that connects to a remote host, retrieves data and outputs it. It may then be accessed by JavaScript, effectively allowing you to make a cross-domain request with AJAX.

2 Comments

+1 Probably not recommended at all, but would definitely work :P
You're right, though it's only a security risk if said script will happily connect to any host and retrieve any data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.