I have a page with an <iframe>
, and inside that <iframe>
another <iframe>
pops up as a window. What I'm trying to do is call a function that is set in the <iframe>
's <iframe>
.... I know, lot's of the same tag going on.
Here's what I mean in HTML format.
<body>
<iframe src="blahblah.html" name="iframe">
//blahblah.html html
<iframe src="blahblahpopup.html" name="iFrame2">
//blahblahpopup.html html, also where the function is set.
</iframe>
</iframe>
</body>
So, as you can see, there is an <iframe>
in an <iframe>
.
Now lets get down to business. I'm using this JS code to get my JS context into the first level <iframe>
with the name 'iframe'
window.frames['iframe'].showAssetPicker();
What that does is it calls the popup inside the first-level <iframe>
. But now I need to call a function inside of the popup that was just called. (which is yet another <iframe>
... I'm not the cause of all the <iframe>
's...)
So here's my failed attempt of calling a function defined in the second-level <iframe>
...
window.frames['iframe'].frames['iFrame2'].populateTypePullDown('/getdata/');
I also tried
window.frames['iframe'].window.frames['iFrame2'].populateTypePullDown('/getdata/');
Neither seem to work. Any help with this? I am using node-webkit to remove <iframe>
security restrictions.
Thanks for any help you can throw my way!
P.S. Goodness gracious, I said <iframe>
far too many times in this post.
I have a page with an <iframe>
, and inside that <iframe>
another <iframe>
pops up as a window. What I'm trying to do is call a function that is set in the <iframe>
's <iframe>
.... I know, lot's of the same tag going on.
Here's what I mean in HTML format.
<body>
<iframe src="blahblah.html" name="iframe">
//blahblah.html html
<iframe src="blahblahpopup.html" name="iFrame2">
//blahblahpopup.html html, also where the function is set.
</iframe>
</iframe>
</body>
So, as you can see, there is an <iframe>
in an <iframe>
.
Now lets get down to business. I'm using this JS code to get my JS context into the first level <iframe>
with the name 'iframe'
window.frames['iframe'].showAssetPicker();
What that does is it calls the popup inside the first-level <iframe>
. But now I need to call a function inside of the popup that was just called. (which is yet another <iframe>
... I'm not the cause of all the <iframe>
's...)
So here's my failed attempt of calling a function defined in the second-level <iframe>
...
window.frames['iframe'].frames['iFrame2'].populateTypePullDown('/getdata/');
I also tried
window.frames['iframe'].window.frames['iFrame2'].populateTypePullDown('/getdata/');
Neither seem to work. Any help with this? I am using node-webkit to remove <iframe>
security restrictions.
Thanks for any help you can throw my way!
P.S. Goodness gracious, I said <iframe>
far too many times in this post.
-
Have you tried using
window.frames['iframe'].contentWindow
instead? – Marco Bonelli Commented May 5, 2015 at 18:55 - Any error in the browser console? – huysentruitw Commented May 5, 2015 at 19:03
- It says the function is not defined. Which means I'm not getting in the correct context.. – Darryl Huffman Commented May 5, 2015 at 19:07
2 Answers
Reset to default 3Probably the issue is that you don't wait before the Asset Picker is loaded and therefore the function populateTypePullDown
is not yet defined.
Try something like this:
$('#iframe')
.ready(function() {
var $innerIframe = $(this).contents().find('#iFrame2');
console.log($innerIframe, 'ready');
$innerIframe.get(0).contentWindow.populateTypePullDown('/vsg/ipm/SecuredOfferRepository');
})
.get(0).contentWindow.showAssetPicker();
Figured out the answer. What I did was I reached inside the main <iframe>
, and got the contentWindow of the <iframe>
inside.
$('#iframe').contents().find('#iFrame').get(0).contentWindow.performSearch();