Reading parent document from iFrame and changing parent

前端 未结 1 1112
盖世英雄少女心
盖世英雄少女心 2020-12-20 16:46

I\'m trying to write a JavaScript application that will load a button up in an iFrame on a page. This application will read the parent document and strip out all images, ap

相关标签:
1条回答
  • 2020-12-20 17:20

    You can reference the parent either by using parent or using the top variable that always points to the outer most document.

    • parent == parent window
    • top == out most window

    So for accesing the first div in the parent window

    var d = parent.document.getElementsByTagName("div")[0];
    

    But as noted already in the comment, both the outer document and the document in the iframe need to be from the same domain or you will be blocked for security reasons.

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