Accessing JavaScript Functions Within an iFrame from the Parent Page
To invoke JavaScript code within an iframe from the parent page, first identify the iframe's ID, such as "targetFrame," and the function to call within the iframe, such as "targetFunction()."
Accessing the iframe:
Example:
// Target the iframe with ID "targetFrame" const iframe = document.getElementById('targetFrame'); // Get the window object of the iframe const iframeWindow = iframe.contentWindow; // Invoke the "targetFunction()" function within the iframe iframeWindow.targetFunction();
The above is the detailed content of How Can I Call a JavaScript Function Inside an iFrame from its Parent Page?. For more information, please follow other related articles on the PHP Chinese website!