javascript - 禁用嵌入的 html

标签 javascript html capture

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

<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/

相关文章:

android - 如何从 android 中运行的视频中捕获图像?

C++ Lambda 捕获弄乱了局部变量值

javascript - 未捕获的类型错误 : object is not a function after second refresh

jquery - 有没有办法强制点击溢出内容来触发点击事件

javascript - 提交后清空表单数据

javascript - 如何从浏览器编辑和保存静态网页?

Java 泛型 : put() on Map<String, 捕获#3-of ? extends AbstractClass> 不适用于参数 (String, AbstractClass)

javascript - 如何让 JavaScript 中的按钮只执行一次代码?

javascript - 函数调用 Jquery 时浏览器卡住

javascript - Backbone this.el 与 this.$el