如何防止多个iframe减慢加载网页的速度

时间:2016-11-23 12:29:31

标签: javascript php iframe

我有一个网页,用户可以点击图标打开弹出窗口。 由于这是在由db输出触发的循环中,因此可以打开250个图标来打开弹出窗口。

弹出窗口使用iframe标记,一页中可以包含250个iframe标记。这会减慢网页速度。如何防止它减慢我的网页速度?

<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;
    });

    popOpen
});
</script>

<div id="popup_edit_bestelling'.$row['id'].'" class="popup_block">
<iframe id="ifr_1_'.$row['id'].'" frameborder="0" width="1100" height="530">
</iframe>
</div>

<?php
echo '<a href="#?w=1100" rel="popup_edit_bestelling'.$row['id'].'" class="poplight" title="'.$lang['form_edit'].'"><img align="center" src="images/icon/edit.png" onClick=\'document.getElementById("ifr_1_'.$row['id'].'").src="bestelling_edit.php?id='.$row['id'].'";\' /></a> ';
?>

JSFiddle

0 个答案:

没有答案