开发者

Trigger from iframe to sibling iframe

iframe.html

<html>
<head>
    <meta http-equiv="Content-Type" content="text/htm开发者_JS百科l; 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜