相关疑难解决方法(0)

jQuery iframe load()事件?

有谁知道是否有这样的事情?

我有一个插入的iframe,$.ajax()我想在iframe的内容完全加载后做一些事情:

....
 success: function(html){  // <-- html is the IFRAME (#theiframe)
          $(this).html(html);   // $(this) is the container element
          $(this).show();
          $('#theiframe').load(function(){
             alert('loaded!');
          } 
....
Run Code Online (Sandbox Code Playgroud)

它工作,但我看到IFRAME被加载两次(警报也显示两次).

javascript ajax iframe jquery

51
推荐指数
3
解决办法
17万
查看次数

jquery在iframe中侦听事件

我正在使用jquery创建一个非常简单的富文本编辑器...我不想使用第三方.

我需要在iframe(同一个域等)中监听事件,从键入开始.显然我需要经常使用bind().

这就是我目前在IE8中工作得很好(非常令人惊讶)但不是Chrome.

<script>
$(function() {
    $('#text').contents().bind("keyup keydown keypress", function(e) {
        var code = e.keyCode || e.which;
        alert(code);
        return false;
    });
});
</script>

<body>
    <iframe id="text" name="text" src="edit.html"></iframe>
</body>
Run Code Online (Sandbox Code Playgroud)

在上面的关键新闻事件中,我还想获得'edit.html'的当前值并使用该值更新textarea ...

任何帮助将非常感激 :)

非常感谢

编辑:进一步解释,edit.html是一个可编辑的文件使用 "document.body.contentEditable = true;"

-

编辑2:

edit.html =

<script language="javascript">
    function InitializeIFrame() {
        document.body.contentEditable = true;                         
    } 

</script>
<html>
<body onload="InitializeIFrame();">

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

iframe jquery rte

9
推荐指数
1
解决办法
2万
查看次数

监听 iframe 中的鼠标单击和按键事件

我想为嵌入式swipe.to演示文稿的每张幻灯片添加一些解释。因此,我试图计算按下 iframe 中的按钮或完成某些按键的次数。目标是确定用户在哪张幻灯片上,以便显示适当的幻灯片说明。

如果用户单击带有 id 的链接#next或按空格键或右箭头,则整数应该增加。如果用户单击带有 id 的链接#previous或按左箭头,则整数应该减少。

关于鼠标点击事件这个答案对我帮助很大。它就像一个魅力。然而,我仍然很难让按键事件正常工作。

这就是我所得到的:

嵌入代码

<figure class="swipe">
   <iframe src="https://www.swipe.to/embed/0882x" allowfullscreen></iframe>
</figure>
<style>figure.swipe{display:block;position:relative;padding-bottom:56.25%;height:0;overflow:hidden;}figure.swipe iframe{position:absolute;top:0;left:0;width:100%;height:100%;border:none;}</style>
Run Code Online (Sandbox Code Playgroud)

确定幻灯片计数的代码

<script>
        $('body iframe').load(function(){
            var i = 0;
            $('body iframe').contents().find('#next').bind('click',function(e) {
                    i++;
                    alert(i);
            });

            $('body iframe').contents().bind('keypress',function(e) {
                    if(e.keyCode == 32){
                        i++;
                        alert(i);
                    }
            });

            $('body iframe').contents().bind('keypress',function(e) {
                    if(e.keyCode == 39){
                        i++;
                        alert(i);
                    }
            });

            $('body iframe').contents().find('#previous').bind('click',function(e) {
                    i--;
                    alert(i);
            });

            $('body iframe').contents().bind('keypress',function(e) {
                    if(e.keyCode == 37){
                        i--;
                        alert(i);
                    }
            });


        });
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript iframe jquery

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

iframe ×3

jquery ×3

javascript ×2

ajax ×1

html ×1

rte ×1