I have a document (child) nested within a (parent) frame using an iframe.

我有一个使用iframe嵌套在(父)框架内的文档(子)。

I need to retrieve a DOM element with mouse coordinated in the child using [elementFromPoint()][1] from the parent.

我需要使用来自父级的[elementFromPoint()] [1]在子级中协调鼠标来检索DOM元素。

Script works fine on latest Chrome and Firefox but on IE 11 it returns always null.

脚本在最新的Chrome和Firefox上工作正常,但在IE 11上,它返回始终为null。

I need to know what could be the problem using IE and a possible solution or work around.

我需要知道使用IE和可能的解决方案或解决方法可能存在什么问题。

Notes: script does not work on IE even if the document are on the same domain.

注意:即使文档位于同一域中,脚本也无法在IE上运行。

Example here, please click orange box: http://jsbin.com/masusekude/1/

例如,请点击橙色框:http://jsbin.com/masusekude/1/

document.getElementById('main').addEventListener('click', function (e) {
                    var elm = document.getElementById('iframe').contentDocument.elementFromPoint(e.pageX, e.pageY);
                    alert(elm);
                }.bind(this));

1 个解决方案

#1


1

I found what was wrong in my case, maybe you check yours too. In my case, I have an div element that was hiding the iframe content and capturing the mouse movements.

我发现我的情况有问题,也许你也检查一下。在我的例子中,我有一个div元素隐藏iframe内容并捕获鼠标移动。

What I could see is that, in IE, if you have an HTML element that is in front of the iframe content, calling 'iframe.contentWindow.elementFromPoint(x, y)' will return null in that case.

我可以看到,在IE中,如果你有一个位于iframe内容前面的HTML元素,那么在这种情况下调用'iframe.contentWindow.elementFromPoint(x,y)'将返回null。

The fix for my issue was to hide that div just to call the elementFromPoint and show it back again after that.

我的问题的解决方法是隐藏该div只是为了调用elementFromPoint并在此之后再次显示它。

更多相关文章

  1. Jquery中动态添加元素的绑定事件不起作用
  2. 有没有办法检查两个数组是否具有相同的元素?
  3. 如何从json对象获取匹配元素的索引?
  4. 为什么我不能删除数组的元素?
  5. jQuery插件:如何将元素引用传递给回调函数?
  6. 浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本
  7. 像C#一样,去写Javascript----记我的脚本库RockSniper.Scripts.js
  8. js的html元素的父节点,子节点
  9. 在关联数组中移动元素[重复]

随机推荐

  1. 安卓---EditText控件的使用
  2. 【Android】RelativeLayout相对布局属性
  3. android下eclipse中This LinearLayout la
  4. android布局RelativeLayout中android:gra
  5. Android 开发————1、Android基础简介
  6. Android Trick 2: Android中的透明属性的
  7. Android UI之GridView
  8. Android 中启动自己另一个程序的activity
  9. Android:安卓资源引用符号的含义
  10. 【译】Android系统简介