繁体   English   中英

如何从 iframe 过渡到 JS 中的页面?

[英]How to make a transition from an iframe to a page in JS?

我有一个 html 页面,当单击一个按钮时,它会打开一个 iframe 页面。
在 iframe 我做了一个按钮来关闭它,但它不起作用。
iframe 和页面都是同一个站点!

let closeBtn = document.querySelector ("# close_btn"); // The "cross" button in the iframe
closeBtn.onclick = function () {

     write.classList.add ("write-off"); // Add the class to the main HTML page
     dimming.classList.add ("write-dimming-off"); // Add the class to the main HTML page
};

它也不起作用。

let closeBtn = document.querySelector ("# close_btn");
closeBtn.onclick = function() {

    window.parent.document.querySelector(".write").classList.add("write-off");
    window.parent.document.querySelector(".write-dimming").classList.add("write-off");
};

为您的 iframe 分配一个 ID,例如 <iframe id="Closed"...

然后你需要一个 function 来移除 iframe

<a href="javascript: window.parent.document.getElementById('Closed').parentNode.removeChild(window.parent.document.getElementById('Closed'))">Close</a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM