admin管理员组文章数量:1384229
I am trying to get elements in html page, i use document.elementFromPoint(x,y) to detect input elements; it works fine when there are no iframes. But inside iframes it does not work inside this code
the html as follow
Am I missihng something?
<html>
...
<div>
<div>
<iframe src="some source"..>
<html>
..
<form>
<fieldset>
<input>
Thanks
I am trying to get elements in html page, i use document.elementFromPoint(x,y) to detect input elements; it works fine when there are no iframes. But inside iframes it does not work inside this code
the html as follow
Am I missihng something?
<html>
...
<div>
<div>
<iframe src="some source"..>
<html>
..
<form>
<fieldset>
<input>
Thanks
Share Improve this question edited Jan 10, 2012 at 22:11 Anass Kartit asked Jan 10, 2012 at 22:10 Anass KartitAnass Kartit 2,09815 silver badges26 bronze badges2 Answers
Reset to default 5As per the documentation here:
"If the element at the specified point belongs to another document (for example, an iframe's subdocument), the element in the DOM of the document the method is called on (in the iframe case, the iframe itself) is returned."
Meaning that it should return the iframe if your current DOM context is the iframe's parent. Also there are cross domain security issues you should read up on if the iframe is from another domain.
If it is from your domain and you wish to get the element inside of the iframe you would do the following:
var el = document.elementFromPoint(x, y);
if (el instanceof HTMLIFrameElement)
el = el.contentWindow.document.elementFromPoint(x, y); //Not sure if you need to update x, y to account for being inside another dom.
If your iframe is not on the same domain as your website, you won't be able to select tags using jquery/javascript
本文标签: javascriptdocumentelementFromPoint(xy) to get element inside iframeStack Overflow
版权声明:本文标题:javascript - document.elementFromPoint(x,y) to get element inside iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744457451a2607067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论