Only load div iframe onclick

前端 未结 3 1926
予麋鹿
予麋鹿 2020-12-05 08:31

I have this part of code. When the page is loaded also all div\'s are loaded but not yet visible. Is the an way to start loading the content of the div when it\'s clicked? N

相关标签:
3条回答
  • 2020-12-05 08:43

    Do you mean load the iframe inside the div only when an element is clicked? If so you can delete the iframe src attribute from the iframe tag and set the src only when the element is clicked.

    On the iframe:

    <iframe id='ifr' frameborder="0" scrolling="no" width="550" height="400">
    

    On the clickable element:

    onClick='document.getElementById("ifr").src="add_dossier.php";'
    
    0 讨论(0)
  • 2020-12-05 09:03
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
    <script type="text/javascript">
    $(function(){
        $('#button').click(function(){
            if(!$('#iframe').length) {
                    $('#iframeHolder').html('<iframe id="iframe" src="http://google.com" width="700" height="450"></iframe>');
            }
        });   
    });
    </script>
    
    <a id="button">Button</a>
    <div id="iframeHolder"></div>
    
    0 讨论(0)
  • 2020-12-05 09:07

    jQuery makes it easy!

    Load below in the <head> section.

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
    <script>
    jQuery(function(){
        $("iframe").each(function(){
            this.tmp = this.src;
            this.src = "";
        })
        .parent(".popup_block")
        .click(function(){
            var frame = $(this).children("iframe")[0];
            console.log(frame);        frame.src = frame.tmp;
        });
    });
    </script>
    
    0 讨论(0)
提交回复
热议问题