user3656313
user3656313

Reputation: 9

iframe accessing child JavaScript of source

I have been trying to access a html source file through iframe. It works fine and I can see the source, but my external JavaScript file doesn't work through the iframe.

So far this is what I have for accessing the HTML file.

<iframe src="Example.html">
     <p>Your browser does not support iframes.</p>
</iframe>

and then in Example.html I have:

<script src="SpinScript.js"></script>

This works if I run the HTML file in any browser, but not through the iframe

In this HTML file I have other JavaScript elements but they are just written in this document and they work fine through the iframe.

What I'm wondering is if have to re-establish where the JavaScript file is in the iframe?

Hope that all makes sense and thanks for your time.

Upvotes: 0

Views: 58

Answers (1)

writeblacknwhite
writeblacknwhite

Reputation: 11

Your parent window and iframe should be from the same source (url), then you can use window.frames[framename] to get window object in iframe

Upvotes: 1

Related Questions