Calling javascript function in iframe
Use:
document.getElementById("resultFrame").contentWindow.Reset();
to access the Reset function in the iframe
document.getElementById("resultFrame")
will get the iframe in your code, and contentWindow
will get the window object in the iframe. Once you have the child window, you can refer to javascript in that context.
Also see HERE in particular the answer from bobince.
Invoking JavaScript code in an iframe from the parent page
Assume your iFrame's id is "targetFrame" and the function you want to call is targetFunction()
:
document.getElementById('targetFrame').contentWindow.targetFunction();
You can also access the frame using window.frames
instead of document.getElementById
.
// this option does not work in most of latest versions of chrome and Firefox
window.frames[0].frameElement.contentWindow.targetFunction();
Call JavaScript function inside an different iframe
Found a way to do and not using postMessage API
On caller iframe (iframe2), I call an JS function located at parent document
onclick="changeCenter({lat:-20.419528,lng:-54.576573})"
On parent has a function that recalls a function inside iframe1 passing parameter
function MapCenter(center)
{
document.getElementById("IFRAME1").contentWindow.changeCenter(center);
}
Finally inside iframe1 is the function that will execute the action on iframe1
function changeCenter(center)
{
map.setZoom(15);
map.setCenter(center);
}
Calling javascript function in iframe
Use:
document.getElementById("resultFrame").contentWindow.Reset();
to access the Reset function in the iframe
document.getElementById("resultFrame")
will get the iframe in your code, and contentWindow
will get the window object in the iframe. Once you have the child window, you can refer to javascript in that context.
Also see HERE in particular the answer from bobince.
Call a javascript function from an iframe
You can use window.parent
to access the containing page:
window.parent.someToggleFunc();
Note that Javascript access between iframes like this are subject to the Same Origin Policy.
Related Topics
How to Terminate the Script in JavaScript
Create Array of Unique Objects by Property
Optimum Way to Compare Strings in JavaScript
Why Is My Onclick Being Called on Render? - React.Js
React: Why Child Component Doesn't Update When Prop Changes
How to Tell If a Browser Supports <Input Type='Date'>
Html/Javascript: Simple Form Validation on Submit
JavaScript Code Not Work in Head Tag
How to Wrap Part of a Text in a Node with JavaScript
Img-Src' Was Not Explicitly Set, So 'Default-Src' Is Used as a Fallback
How to Wait for a JavaScript Promise to Resolve Before Resuming Function
Rails 4 Turbo-Link Prevents Jquery Scripts from Working
How to Get the Status Code from an Http Error in Axios
Has Facebook Sharer.PHP Changed to No Longer Accept Detailed Parameters
Jquery - Sticky Header That Shrinks When Scrolling Down
HTML "Data-" Attribute as JavaScript Parameter
Selecting Multiple from an HTML Select Element Without Using Ctrl Key