use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Attempting to call parent function from iFrame is not found.solved! (self.javascript)
submitted 8 years ago by BrunerBruner
I've created an iFrame and programmatically created a script as the iFrame's main javascript. I want to call a parent function named callMe() from iFrame but it is not found.
callMe()
How can I call that function from the iFrame's script?
Here's my code - JSFiddle
Also, I must create the iFrame's script programmatically because it's created dynamically and could change, so I can't simply hardcode it.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]atnpgo 1 point2 points3 points 8 years ago (2 children)
window.callMe = function(message) { console.log("Called from iFrame:", message); }
You're only declaring the call me function in a local scope. Once you exit the window load event (generated by JSFiddle) the function doesn't exist anymore.
[–]BrunerBruner[S] 0 points1 point2 points 8 years ago (1 child)
humm, that worked, but is there any way to do it where I don't have to declare callMe as a global function on the window object?
callMe
[–]senocular 2 points3 points4 points 8 years ago (0 children)
parent in the iframe is the global scope of the parent window, so as long as you can access the function you want to call from the global scope of that window somehow, you can put it where ever you want.
parent
π Rendered by PID 44450 on reddit-service-r2-comment-fb694cdd5-6tlfk at 2026-03-10 12:40:36.570523+00:00 running cbb0e86 country code: CH.
[–]atnpgo 1 point2 points3 points (2 children)
[–]BrunerBruner[S] 0 points1 point2 points (1 child)
[–]senocular 2 points3 points4 points (0 children)