4

Possible Duplicate:
jQuery/JavaScript: accessing contents of an iframe

If i run this on my localhost, it works fine, as long as the src if the iframe is on localhost aswell..

But as soon as i get it online, it doesent do a thing...

http://jsfiddle.net/WnwRc/9/

The goal right now is simply to alert the HTML that is loaded in to the iframe.

Community
  • 1
  • 1
BjarkeCK
  • 5,694
  • 5
  • 41
  • 59
  • 3
    Ever heard about the [Same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy)? – Rob W Mar 08 '12 at 21:02
  • Maybe [this](http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) answers it. – Thorsten Mar 08 '12 at 21:03
  • @Rob W - So downloading the html content of fx ted.com and replaceing it's the local urls to online urls, so that i can display the ted.com page on a domain of my own and then displaying that page in a iframe, would be okay? Or is it illigal? – BjarkeCK Mar 08 '12 at 22:06
  • @BjarkeCK From the [Terms of use](http://www.ted.com/termsofuse): "9. Please help spread TED.". If you clearly state that the content is from Ted.com, and link correctly, I don't think that the webmaster is going to chase you. Don't take my words for legal advice though. – Rob W Mar 08 '12 at 22:15

2 Answers2

5

A security feature in browsers prevents you from accessing certain DOM objects inside iFrames whose document.domain property is different from the accessing iFrame.

If you're trying to do some web scraping or automation via an iFrame, I'm afraid that's not going to work very well.

Here's a quick link with tons of information for iFrame do's and don'ts: http://softwareas.com/cross-domain-communication-with-iframes

mroselli
  • 151
  • 5
1

Load Event doesn't bubble as properly as per jquery website

http://api.jquery.com/load-event/

Note: The .live() and .delegate() methods cannot be used to detect the load event of an iframe. The load event does not correctly bubble up the parent document and the event.target isn't set by Firefox, IE9 or Chrome, which is required to do event delegation.

coool
  • 8,085
  • 12
  • 60
  • 80