gpt4 book ai didi

javascript - 禁用嵌入的 html

转载 作者:行者123 更新时间:2023-11-28 07:39:22 24 4
gpt4 key购买 nike

我想将另一个页面嵌入到我页面的表格中。有(至少)三种方法可以做到这一点:

<table><tbody><tr>
<td><object id="A" type="text/html" data="othersite.html"></object></td>
<td><embed id="B" src="othersite.html"></td>
<td><iframe id="C" src="othersite.html></iframe></td>
</tr></tbody></table>

但是,我不希望这些嵌入页面响应鼠标单击事件。

我知道安全性阻止我捕获事件:

document.addEventListener("click", function() { console.log("Click captured and discarded"); }, true); // this is forbidden

但我希望能够做类似的事情

document.getElementById("A").disabled = true; // this should work but doesn't

还有其他方法可以让嵌入的html忽略点击事件吗?

谢谢。

附注抱歉,我无法给您提供示例,但 jsfiddle 似乎可以阻止嵌入 html。

最佳答案

您可以在 iframe 顶部放置一个透明的 div:

iframe, div {
position: absolute;
height: 500px;
width: 500px;
}
<iframe id="C" src="http://wikipedia.com"></iframe>
<div></div>

关于javascript - 禁用嵌入的 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28240655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com