getElementById within iframe

前端 未结 3 810
眼角桃花
眼角桃花 2021-01-21 07:52

Q: I have an iframe calling page X, on page X is a div w/ id=test. The value of this test div is \"bubbles\". On the parent page I need to read the value of the div

相关标签:
3条回答
  • 2021-01-21 08:18

    You will still be blocked by the same-origin policy if the domains mismatch. Doesn't matter if you're just trying to grab a value.

    0 讨论(0)
  • 2021-01-21 08:20

    As Alex says on the comment above, you will still be blocked by the JavaScript 'same-origin' policy.

    If your iframe is on the same domain, then you could try this:

    document.getElementById('iframe-id').contentDocument.getElementById('canvas');
    
    0 讨论(0)
  • 2021-01-21 08:31

    Assuming the iFrame has an assigned ID:

    var iframe_div = document.getElementById('iframeid').document.getElementById('mydiv');
    var content = iframe_div.innerHTML;
    

    I believe should work.

    0 讨论(0)
提交回复
热议问题