Can I run .js on iFrames?

Hello & Thanks ;
Can I run .js with iFrames ?
See Example .
From main html , I would like to trigger a js function on a hover over link ,
and on a click-on-link
happening in the iFrame .
Is this sort of thing do-able ?
Thanks

<!DOCTYPE html>
<html>
<body>

<h2>Iframe - Target for a Link</h2>

<iframe src="demo_iframe.htm" name="iframe_a" height="300px" width="100%" title="Iframe Example"></iframe>

<p><a href="http://www.vmars.us" target="iframe_a">http://www.vmars.us</a></p>

<p>When the target attribute of a link matches the name of an iframe, the link will open in the iframe.</p>

</body>
</html>

Iframe - Target for a Link

http://www.vmars.us

When the target attribute of a link matches the name of an iframe, the link will open in the iframe.

As I know, you can reach HTML-element in iFrame and init there an event. Direct access to .js function in iFrame, I think, impossible.

Hi @vmars316, if the iframe is on the same domain as the host page, you can access it’s window and document via its contentWindow and contentDocument properties, respectively:

2 Likes

same domain as the host

Yes that’s a problem .
I am thinking
a better approach might be to <embed> an html page .
Any thoughts ?
Thanks