iframe 显示和自己关闭


iframe 显示和自己关闭

  • 父html

其中tc/index.html为子html

1
<iframe id="tc" src="tc/index.html" allowfullscreen="" allow="autoplay" width="100%" height="100%" style="border: 0px; opacity: 1; margin: 0px; padding: 0px; position: relative; display: none;"></iframe>

js 打开关闭方法

1
2
3
4
5
6
7
8
function showTC() {
var tc = document.getElementById('tc');
tc.style.display = 'block';
}
function closeTC() {
var tc = document.getElementById('tc');
tc.style.display = 'none';
}
  • 子html

调用父html的js关闭方法

1
window.parent.closeTC();