1

i have the following code

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

but when i click the button, nothing seems to happen

4 Answers 4

1

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>');
    }
});
Sign up to request clarification or add additional context in comments.

5 Comments

I think i know what the problem might be. The button is a submit button, is there a way to make the page wait until the iframe loads and then continue along with the submit?
Unfortunately, as of the last WebKit update, document.write() has been deprecated and there's no callback for the load of an iframe. Fortunately, brilliant users have come up with this: stackoverflow.com/questions/164085/…
I use the iframe code by itself without attaching it to the button and it definitly works so i know the problem is with the submit button.
I don't actually need a call back, just for the page to stop doing anything until the iframe loads, then it can continue with the "submit". ANy ideas?
You want it all to wait until the full iframe has been loaded? That's a callback. Can you explain why you want everything to wait? Maybe there's a very easy solution.
1

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.

1 Comment

I think i know what the problem might be. The button is a submit button, is there a way to make the page wait until the iframe loads and then continue along with the submit?
1

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

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

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.