【问题标题】:Bubble up mousemove event on iframe to the container div将 iframe 上的 mousemove 事件冒泡到容器 div
【发布时间】:2015-09-10 11:52:10
【问题描述】:

我有以下代码

<div onmousemove="myFunction()">
  <iframe src="www.someotherdomain.com"/>
</div>

我希望在用户将鼠标移到 iframe 上时执行 myFunction。是否可以将 iframe 上的事件冒泡到跨域场景中的父元素?我将如何做到这一点?

PS:- 我无法使用中提供的解决方案

Iframe obstructing the mousemove event from occuring

How do you send a mousemove event from an iframe back to the parent using jquery?

因为我希望用户能够与 iframe 中的内容进行交互。

【问题讨论】:

  • 我 99.999% 确定你是 SOL
  • 不知道你在追求什么。 jsfiddle.net/L5bsxykw ?
  • 这是在 div 本身上生成的 mouseover 事件。效果很好。但是 mousemove 事件是在 iframe 上生成的,不会传播到 div
  • 您真正想要实现什么?为什么需要知道用户在来自不同域的 iframe 文档中使用鼠标做了什么?
  • 我的主站点上有一个会话超时,如果用户在一段时间内不活动,它将注销用户。这个 iFrame 在我的网站中占据了很大一部分,用户可以在其中花费大量时间做事。我不希望用户超时,因为他在网站的其他部分处于非活动状态。

标签: javascript jquery html iframe


【解决方案1】:

我只能看到一种方式。

鼠标移入 iframe 时禁用会话计时器,鼠标​​移出时启用它。

为此,请在 div 中添加一个边距,然后在外部 div 中使用 mouseenter 和 mouseleave,反之亦然。

如果窗口失去焦点,您可能还需要启用计时器

【讨论】:

  • 如果用户在 iFrame 上实际上是空闲的,这不会注销用户
  • 我知道 - 如果您无权访问 iframe 内容,那么这是您能做的最好的事情
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-20
  • 2011-08-23
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
相关资源
最近更新 更多