gpt4 book ai didi

javascript - iframe onmouseout 捕获

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:07:51 27 4
gpt4 key购买 nike

我目前在我的父页面中有一个 iframe,我想知道是否可以捕获 onmouseout 事件以在用户单击或移动到 iframe 边框之外(即返回父页面)时捕获。

最佳答案

您应该能够在 iframe 的页面中执行 document.body.onmouseleave/onmouseout(请参阅编辑)。由于它会冒泡,因此您必须检查它是否真的是激发事件的主体。

document.body.onmouseout = function ()
{
if (event.srcElement == document.body)
{
// put your code here
}
}

编辑:我的错误是,onmouseleave 不会冒泡,因此没有必要使用 if 语句。 onmouseleave 不适用于其他浏览器,因此您应该使用 onmouseout 并保留 if 语句,因为 onmouseout 确实会冒泡。

如果您只关心 IE6,请将以下 <script> 标记放入您的 iframe 页面的代码中(最好是页眉)。

<script type="text/javascript">
document.documentElement.onmouseleave = function ()
{
alert('mouse left the iframe');
}
</script>

请参阅 MSDN 文档 here

关于javascript - iframe onmouseout 捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1058085/

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