Script visibility includes in IFRAME
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 function call from FromScriptJS () does not work.
The first guess parent.functionFromScriptJS () doesn't work either.
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 an iframe tag and I could put it in a separate file and specify it via the src attribute of the tag. In this case, parent.functionFromScriptJS () works.
source to share
Iframes do not support inline content. you must use the src attribute to link to another file. The inner text of the tag <iframe>
will be displayed in browsers that do not support iframe.
Example:
<iframe src="someFile.html" width="100%" height="300px">
<p>Your browser does not support iframes.</p>
</iframe>
After you load the page, you should be able to call the script with parent.functionFromScriptJS();
source to share