0

Possible Duplicate:
how to get body content of iframe by javascript?

I am creating a Chrome extension and I want to be able to access an element within an iframe. So far I am able to access the iframe, but when i go to access the element I want it returns the error "Uncaught TypeError: Object # has no method 'getElementById'". the canvas element in the iframe has id of "canvas".

    var divElement, iframeElement, canvasElement;

    if (document.getElementById("puzzle")) {
      divElement = document.getElementById("puzzle");
      iframeElement = divElement.getElementsByTagName("iframe")[0];
      canvasElement = iframeElement.getElementById("canvas");
      console.log(canvasElement);
    }
Community
  • 1
  • 1
Daniel
  • 4,202
  • 11
  • 50
  • 68

1 Answers1

0

Does the iframe have a different domain from the site that's trying to access it? Cross-site scripting is prohibited by the same-origin policy, and this may be why you are not seeing the element you want.

Lawrence H
  • 467
  • 4
  • 10