1

iframe.html

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript"></script>
    <script>
    $(function(){

    });
    </script>
</head>
<body>


<table border="1" width="100%" height="100%">
  <tr>
    <th><iframe id="i1" width="100%" height="100%"src="iframe_file1.html"></iframe></th>
    <th><iframe id="i2" width="100%" height="100%"src="iframe_file1.html"></iframe></th>
  </tr>
 
</table>

</body>
</html>

iframe_file1.html

<html>
 <head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
 <script>
 $(document).ready(function(){
        $('body').click(function(e){
            console.log("iframe clickq1");
            console.log(e);
            $('#i2', window.parent.document).contents().find('body').trigger(e);
        });
 });
 </script>
 </head>
    <body>
            <a href="#" onclick="alert('first link')">first link</a>
            <input type="button" value="Click me" id="button_click">
    </body>
</html>

When click on link or button event is trigger but it is not triggering on second iframe if change i2 to i1 in this line:

$('#i2', window.parent.document).contents().find('body').trigger(e);

then its working. Why i2 is not working and what should I do?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
XMen
  • 29,384
  • 41
  • 99
  • 151
  • 2
    possible duplicate of [Triggering event on the other iframe from an iframe](http://stackoverflow.com/questions/7226741/triggering-event-on-the-other-iframe-from-an-iframe) ... please don't ask questions multiple times (you already asked that question at least twice). Edit your original question to provide more information and you can set a bounty to draw attention to it. – Felix Kling Aug 29 '11 at 10:09
  • Please provide a demo, your code works fine as it is. – Dr.Molle Aug 29 '11 at 10:43
  • when i click on the button the body click event fires , at this point i also want to fire the click of the button in the #i2 but it is not happening – XMen Aug 29 '11 at 10:46

0 Answers0