打开手风琴后动态更改iframe的高度

时间:2019-02-01 17:11:34

标签: javascript iframe addeventlistener

我有一些角度应用程序,它将被集成在iframe中。它已经改变了高度动态的,而不是打开后手风琴。每次点击后,我都会调用该事件。但这没有帮助。这是我的代码:

let observer = null;
window.addEventListener("click", function(){
  document.getElementById('id').style.height = document.getElementById('id').contentWindow.document.body.scrollHeight + 'px';
});

window.addEventListener('load', function () {
  const config = {
    'childList': true,
    'attributes': true,
    'characterData': false,
    'subtree': true,
    'attributeOldValue': true,
    'autoResize': true,
    'attributeFilter': ['clientHeight', 'offsetHeight']
  };
  const callback = function (mutationsList) {
    if (window.parent) {
      window.parent.postMessage(['setHeight', document.body.offsetHeight], '*');
    }
  };
  observer = new MutationObserver(callback);
  observer.observe(document, config);
}, false);
window.addEventListener('unload', function () {
  observer.disconnect();
}, false);

但我得到一些错误:无法读取空的特性“风格” 可能是有人给意见,为什么它不工作。 预先感谢。

0 个答案:

没有答案
相关问题