JS Coding Questions Logo
JS Coding Questions
#293💼 Interview💻 Code

How do you invoke javascript code in an iframe from the parent page

Advertisement

728x90

Initially iFrame needs to be accessed using either document.getElementBy or window.frames. After that contentWindow property of iFrame gives the access for targetFunction

javascript
1document.getElementById("targetFrame").contentWindow.targetFunction();
2
3window.frames[0].frameElement.contentWindow.targetFunction(); // Accessing iframe this way may not work in latest versions chrome and firefox

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 37

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
293of476
How do you invoke javascript code in an iframe from the parent page | JSCodingQuestions.com