For example:
script.js:
function functionFromScriptJS() { alert('inside functionFromScriptJS'); }
iframe.html:
<html> <head> <script language='Javascript' src='script.js'></script> </head> <body> <iframe> <body> <script language='JavaScript'> functionFromScriptJS(); </script> </body> </iframe> </body> <html>
The above call to functionFromScriptJS() is not working.
The first guess parent.functionFromScriptJS() is not working too.
Is it possible to access such an external function from an iframe when the include is not in the iframe itself but in the parent document?
@Edit: So my mistake was that I put the document inside the iframe tag, and I sould have put it in a separate file and specified through the src attrubute of the tag. In this case parent.functionFromScriptJS() works.
Iframes do not support inline content. you must use the src attribute to reference a different file. The inner text of the
<iframe>tag will be displayed to browsers that do not support iframes.Example:
Once you have your page loading then you should be able to call the script using
parent.functionFromScriptJS();