1

Okay, I have a big problem today. I've just created a site with an iframe with src="somedomain.com/somepage.html", but I don't know the way to access the jQuery, which the somepage.html includes. I know of CORS, but I can also run functions in iframe with parent page. So is there any way to run jQuery object functions inside the iframe from parent page?

Note: I can't chnage content of somepage.html.


I tried the following:

mainIframe.contentWindow.$

but the console gave an error:

Error: Permission denied to access property "$"

It is really possible? If yes, how can I do that?

Thanks in advance.

5
  • 2
    You're not allowed to access a frame from another domain. Commented May 19, 2015 at 19:37
  • stackoverflow.com/questions/3175006/… Commented May 19, 2015 at 19:39
  • Can you add anything at all to the parent page? A snip of javascript perhaps? If no, then you're stuck. Allowing the document inside the iframe to modify the parent document poses security concerns, which is why it's not allowed. Commented May 19, 2015 at 19:43
  • @MartyMulligan I can change whatever I want to in parent page, but I can't in iframe. I don't know if I understand right. I don't want to modify parent page from iframe, but I want to access jQuery from parent page :) Commented May 19, 2015 at 19:46
  • Sorry, my mistake. If you have any access at all to the frame contents (even one time) you can communicate between iframes by posting / intercepting "message" events. Otherwise, yeah like the accepted answer says. Commented May 19, 2015 at 20:06

1 Answer 1

3

You cannot access a child frame from a different domain. It's a security reason. If you could access data inside a child frame that is in a different domain, it would be easy enough to simulate fake pages.

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

4 Comments

Great, but what about forms etc?
I don't think it's possible to access anything in a child frame that is in a different domain. And I think that it's great that way. Security concerns.
Well, it seems I have no choice, I'll use PHP's php.net/manual/en/function.file-get-contents.php :) Thanks anyway...
Although you can't directly access the child frame, you can send data from the child frame to the parent page using window.postMessage.

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.