简体   繁体   中英

Capture ajax events inside in an iframe from parent window

How can we capture an ajax event inside an iframe completely from parent window scope? either using jquery or normal javascript?

like, the code in parent window is ,

<body>
<iframe class="childframe" src="http://localhost/ajax-page.php"></iframe>
</body>

and the ajax-page.php contains,

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
jQuery(document).ready(function($){
  $.ajax({
    url:'http://localhost/',
    complete: function(data){
       alert('ajax complete inside iframe');
    }
  });
});
</script>

I want to trigger a function in parent window when the ajax event is completed inside iframe.

如果父框架和子框架位于同一域(在这种情况下均为本地主机,那么我假设它们都在):

window.parent.myFunctionInParent();

use http://www.jacklmoore.com/colorbox/

Example:

$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});

<p><a class='iframe' href="http://wikipedia.com">Outside Webpage (Iframe)</a></p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM