仅在单击元素时才将iframe加载到div中

时间:2016-10-11 19:04:31

标签: javascript html

加载页面时,所有div都已加载但尚未显示。有没有办法在点击时开始加载div的内容?现在,由于所有div,页面速度变慢了。我已经测试过这个除了一个div而且除了页面之外的所有内容都要快得多。

如何在点击链接之前阻止加载所有数据?

标题

Products

股利

true/false

弹出窗口链接

<script type="text/javascript">
$(document).ready(function(){

    $.fn.popOpen = function(){

        var popID = $(this).attr('rel'); //Get Popup Name
        var popURL = $(this).attr('href'); //Get Popup href to define size

        //Pull Query & Variables from href URL
        var query= popURL.split('?');
        var dim= query[1].split('&');
        var popWidth = dim[0].split('=')[1]; //Gets the first query string value


        //Fade in the Popup and add close button
        $('#' + popID).fadeIn('slow').css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/icon/delete.png" class="btn_close" title="<?php echo $lang['sluit'] ?>" /></a>');

        //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
        var popMargTop = ($('#' + popID).height() + 20) / 2;
        var popMargLeft = ($('#' + popID).width() + 20) / 2;

        //Apply Margin to Popup
        $('#' + popID).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        //Fade in Background
        $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
        $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies
    };

    //When you click on a link with class of poplight and the href starts with a #
    $('a.poplight[href^=#]').live('click', function() {
        $(this).popOpen(); //Run popOpen function on click
        return false;
    });

    //Close Popups and Fade Layer
    //$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('a.close').live('click', function() { //When clicking on the close...
        $('#fade , .popup_block').fadeOut(function() {
            $('#fade, a.close').remove();  //fade them both out
            location.reload(); // reload page
        });
        return false;
    });
});
</script>

Popup

输出

<div id="popup_planning_opmerking'.$row['planning_id'].'" class="popup_block">
                                    <iframe id="ifr_2_'.$row['planning_id'].'" frameborder="0" scrolling="no" width="525" height="300">
                                    </iframe>
                                    </div>

1 个答案:

答案 0 :(得分:0)

如果您在点击链接时有权访问<a><div>元素,那么您是否可以简单地将<iframe>网址添加为{{1}的自定义网址当你使div可见时,我会添加一个新的<a>吗?