2

I have an iframe and I need to get the contents of it and extract some information from this. Is this possible using Javascript?

I have looked somewhere that this is not possible if the other page runs on a different server but I need to confirm this.

2
  • well, could you clarify if your iframe is indeed on a different server? Commented Jun 26, 2012 at 15:05
  • I'll assume the answer is yes. See @dystroy's answer. Here's a great read on the topic: softwareas.com/cross-domain-communication-with-iframes Commented Jun 26, 2012 at 15:14

2 Answers 2

3

If it comes from another server, you need either :

  • a proxy so that your browser thinks it's the same domain (including port)
  • to have the iframe server set the CORS headers
  • to relax the security of your browser (not possible on Chrome and maybe no more possible on Firefox)

In the general case and if you cannot change the server of the iframe content, you can't read its content in javascript.

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

Comments

0

The iframe element has a method called contentWindow which allows you to do that. It will only works if the iframe is on the same server than the document as @dystroy said.

1 Comment

"Scripts trying to access a frame's content are subject to the same-origin policy, and cannot access most of the properties in the other window object if it was loaded from a different domain"

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.