Reputation: 2589
I'm attempting to call a function set in an iframe, from the parent document. Here's what I mean..
INDEX.HTML
<script>
$('#iframe').contentWindow.showAssetPicker();
</script>
<iframe src="test.html" id="iframe">
TEST.HTML
<script>
function showAssetPicker(){
alert('worked!');
//Do a lot
}
</script>
That's what I've got right now. As you can tell, the index should be calling a function defined within the iFrame - but it's not. It's just telling me it's undefined.
Hopefully this makes sense to you. Also, I am using NW.js (node-webkit) to make iFrames completely controlled.
Thanks for any help!
Upvotes: 1
Views: 713
Reputation: 28151
The jQuery-selector returns an array of selected DOM elements. In your case, you would pick the first (and probably only) element:
$('#iframe').get(0).contentWindow.showAssetPicker();
Upvotes: 1
Reputation: 2589
After a day of searching, I found my answer. That will set the javascript context to the iframe, and then call the function.
window.frames['iframe'].showAssetPicker();
Upvotes: 0