Advertisement
hubert17

Call a function from iframe to parent and vice versa

Oct 8th, 2014
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //The following code calls the function that exists in the main window from the iframe window
  2. if(typeof parent.window !== 'undefined' && typeof parent.window.functionName === 'function'){
  3.     parent.window.functionName(); //Call the function only if it exists
  4. }
  5.  
  6. //The following code calls the function that exists in the iframe window from the main window
  7. if(typeof document.frames['iframeName'] !== 'undefined' && typeof document.frames['iframeName'].functionName === 'function'){
  8.     document.frames['iframeName'].functionName(); //Call the function available in the iframe window from the parent window.
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement