iframe onmouseout捕获 [英] iframe onmouseout capture

查看:96
本文介绍了iframe onmouseout捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I currently have an iframe within my parent page and I was wondering whether it's possible to capture a onmouseout event to trap when the user clicks or moves outside the iframe border, i.e back onto parent page.

非常感谢一些帮助。

谢谢。
Tony。

Thanks. Tony.

推荐答案

你应该能够在一个文件中做一个document.body.onmouseleave / onmouseout(见编辑) iframe的页面。由于它会冒泡,你必须检查它实际上是发射事件的主体。

You should be able do a document.body.onmouseleave/onmouseout (see edits) in the iframe's page. Since it bubbles you'll have to check that it was actually the body that fired the event.

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

编辑:我的错误,onmouseleave没有冒泡,所以那里的if语句没有必要。 onmouseleave对其他浏览器不起作用,所以你应该使用onmouseout并保持if语句,因为onmouseout会冒泡。

EDIT: My mistake, onmouseleave doesn't bubble, so the if statement there isn't necessary. onmouseleave doesn't work for other browsers, so you should use onmouseout and keep the if statement in since onmouseout does bubble.

如果你只是对IE6感到不安,那么以下< script>标记到您的iframe页面的代码(最好是标题)。

if you're only bothered about IE6, put the following <script> tag into your iframe page's code (preferably the header).

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

请参阅MSDN文档这里

这篇关于iframe onmouseout捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆