jquery - iframe access denied in IE on some pages

前端 未结 5 1446
深忆病人
深忆病人 2020-12-05 15:36

I\'m the author of printThis, a jquery plugin for printing.

https://github.com/jasonday/printThis

I have a user that has brought up an issue, that I have bee

5条回答
  •  失恋的感觉
    2020-12-05 16:20

    IE works with iframe like all the other browsers (at least for main functions). You just have to keep a set of rules:

    • before you load any javascript in the iframe (that part of js which needs to know about the iframe parent), ensure that the parent has document.domain changed.
    • when all iframe resources are loaded, change document.domain to be the same as the one defined in parent. (You need to do this later because setting domain will cause the iframe resource's request to fail)

    • now you can make a reference for parent window: var winn = window.parent

    • now you can make a reference to parent HTML, in order to manipulate it: var parentContent = $('html', winn.document)
    • at this point you should have access to IE parent window/document and you can change it as you wont

提交回复
热议问题