简体   繁体   English

如何检测iFrame中点击的单词

[英]How to detect word clicked within the iFrame

I have a iframe on my web page. 我的网页上有一个iframe。 is there a way or JS library I can use to know which word user click within the iframe? 有没有一种方法或JS库,我可以用来了解iframe中用户点击了哪个单词?

In short, no. 简而言之,没有。

In long, yes. 没错,是的。

If the iFrame is loaded on the same sub-domain and domain name as the page that contains the iFrame ( www.example.com ), you can interact with it without doing anything special. 如果将iFrame加载到与包含iFrame的页面( www.example.com )相同的子域和域名中,则可以与其进行交互而无需执行任何特殊操作。

If your iFrame is loaded on the same domain, but a different sub-domain ( sub1.example.com , sub2.example.com ), put this line of javascript at the top of your javascript file, in both the iFrame page and the page that contains it: 如果您的iFrame加载在相同的域中,但在不同的子域中( sub1.example.comsub2.example.com ),则将这行javascript放到javascript文件顶部的iFrame页面和包含它的页面:

document.domain = 'example.com';

This will make the iFrame "think" that it is ok to communicate through javascript. 这将使iFrame“认为”可以通过javascript进行通信。

If the iFrame is on an entirely different domain, there is nothing you can do. 如果iFrame位于完全不同的域中,则您无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM