如何制作< iframes>只按一下按钮加载? [英] How do I make <iframes> load only on a button click?

查看:64
本文介绍了如何制作< iframes>只按一下按钮加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我的问题是我的页面加载速度很慢,因为所有的加载都是愚蠢的。我正在提取一个RSS源,如果你单击文章按钮,它将弹出一个包含它的内部的模态。问题是所有的s都是simeltaneously。

Friends, My issue is that my page is really slow to load, because all of the load simeltaneously. I am pulling an RSS feed that if you click on the "article" button it will pop up a Modal that has the inside of it. The problem is that all of the s load simeltaneously.

这里是网站:
http://daisy.camorada.com/

我试过插入一个src但是这不起作用因为我想当页面打开时加载iframe。

I have tried inserting a src into the but that doesn't work because i guess the iframe loads when the page opens.

<button class='btn btn-primary' id='miguel'>TEST ME NOW</button>
        <button class='btn btn-primary' id='jamison'>jamison</button>
        <div id="yoyoyo">
            </div>
            <iframe id="gogo">
                </iframe>

<script>
        $('#miguel').on('click', function() {
            alert('clicked');           
            $('#gogogo').attr('href', 'http://www.google.com');

        });
    </script>
    <script>
        $('#jamison').on('click', function() {
            alert('clicked JAMISON');       
            $("#yoyoyo").html("<h1>HELLO J</h1><br><iframe class='full-iframe' href='http://news.yahoo.com/three-killed-tribal-clash-libya-001717827.html'></iframe>");

        });

    </script>


推荐答案

Html:

<iframe id="myiFrame" data-src="http://my.url" src="about:blank">
</iframe>

在你的jQuery中:

In your jQuery:

$("button").click(function(){
    var iframe = $("#myiFrame");
    iframe.attr("src", iframe.data("src")); 
});

或者如果您想在点击一个按钮时加载所有iframe ...确保它们都有一个 data-src =your.url属性,然后像这样循环:

Or if you wanted to load ALL iframes when you click one button... make sure they all have a data-src="your.url" attribute, and then loop through like this:

$("button").click(function(){
    $("iframe").each(function(){
        $(this).attr("src", $(this).data("src"));
    });
});

这篇关于如何制作&lt; iframes&gt;只按一下按钮加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆