iframe 父子之间通信

// 父页面

window.onload = () => {
  // 调用子方法
  document.getElementById('iframe1').contentWindow.func()
      
  // 操作子dom
  document.getElementById('iframe1').contentDocument.getElementById('content').style.color = "green"
}
// 子页面

// 调用父方法
window.parent.func()

// 操作父dom
window.parent.document.getElementById('container').style.color = "red"

你可能感兴趣的:(iframe 父子之间通信)