简体   繁体   中英

How to detect word clicked within the iFrame

I have a iframe on my web page. is there a way or JS library I can use to know which word user click within the 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.

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:

document.domain = 'example.com';

This will make the iFrame "think" that it is ok to communicate through javascript.

If the iFrame is on an entirely different domain, there is nothing you can do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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