iframe 调用 父页面 javascript方法

父页面方法:
JavaScript / DHTML / AJAX Syntax ( Toggle Plain Text)
    
    
    
    
  1. <script>
  2. function OnFrameButtonClick ( ) {
  3. alert ( "You clicked on a button in the frame" );
  4. }
  5. </script>

子frame方法 JavaScript / DHTML / AJAX Syntax ( Toggle Plain Text)
    
    
    
    
  1. <head>
  2. <script>
  3. function OnButtonClick ( ) {
  4. // check whether the parent window and the OnFrameButtonClick method exist
  5. if (window. parent && parent. OnFrameButtonClick ) {
  6. parent. OnFrameButtonClick ( );
  7. }
  8. }
  9. </script>
  10. </head>
  11. <body>
  12. <button onclick= "OnButtonClick ()">Test</button>
  13. </body>

你可能感兴趣的:(JavaScript,function,iframe,button)