开发者

Create an iframe on button click with jquery?

i have the following code

var url = "url";
$('<iframe />', {
    name: 'frame',
    id:   'frame',
    src: url
}).appendTo('body');    

but when i click the but开发者_如何学Pythonton, nothing seems to happen


Make sure you don't open the same iframe again and again. Check if it exists!

$('#button').click(function() {
    if($('#myIframe').size() == 0) {
        $('<iframe id="myIframe" src="http://stackoverflow.com"></iframe>');
    }
});


Make sure you put this code in a document.ready:

$(function() {
    $('#someButtonId').click(function() {
        var url = "url";
        $('<iframe />', {
            name: 'frame',
            id:   'frame',
            src: url
        }).appendTo('body');    
    });
    return false;
});

Live demo.


The code works correctly as it is right now. The bug is probably elsewhere in the code.

http://jsfiddle.net/qrDnH/1/


its very simple before click on button clear your div innerhtml where is iframe located

like this document.getElementById("mapdive").innerHTML = "";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜