Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only load div iframe onclick

Tags:

html

iframe

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? Now the page is slowed down because of all div's

<a href="#?w=550" rel="popup_add_dossier" class="poplight" title="'.$lang['form_add'].'"><img src="images/icon/new.png" ></a>

<div id="popup_add_dossier" class="popup_block">
<iframe src="add_dossier.php" frameborder="0" scrolling="no" width="550" height="400">
like image 761
Muiter Avatar asked May 16 '11 10:05

Muiter


2 Answers

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";'
like image 61
mck89 Avatar answered Oct 12 '22 11:10

mck89


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>
like image 5
shotasenga Avatar answered Oct 12 '22 12:10

shotasenga