Hello StackOverflow community,
I was having a problem with my <iframe>
and JavaScript. Let's say I have an index.html with an iframe
in the body. Within the index.html
I have this in the <head>
tags:
<script type="text/javascript">
function alertTest() {
alert("Testing");
}
</script>
In the iframe's src="iframe.htm"
(The location is the same domain as index.html). Within that iframe.htm
page I have:
<a href="javascript:void(0);" onclick="window.parent.alertTest();">Click here.</a>
The problem is it is not loading the alert and in Google Chrome returns the error:
"Uncaught TypeError: Property 'alertTest' of object [object DOMWindow] is not a function
I have tried window.parent.alertTest();
, window.top.alertTest();
, top.alertTest();
, parent.alertTest();
and nearly everything that came up on similar problems I searched.
It seems you are unable to call a function located in a non-iframe, from the iframe located within said non-iframe.
Please help!
P.S. Essentially in the actual final outcome I'm trying to call a Lightbox open image function (Using slimbox because I am able to call the open image function with it from javascript rather than from a href). I have also tried in this final outcome using the target="_parent" property.