Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear/Empty IFRAME which gets fed it's src by jQuery?

I got an iframe inside a modal which starts on "about:blank" and does get fed src's by jquery.

This works alright already, but when the iframe src is set to change, there is always a delay where the modal will still show the old content, while loading the new.

How can I instantly clear the iframe before a new src is given?

Here some code:

$(function() {
      $('a.modal-k2-<?php echo $this->item->id; ?>').click(function() {
            window.top.$('#modalHolderK2_title').text('<?php echo $author->name . ' - ' . $this->item->title; ?>');
            if (window.top.$('#modalHolderK2_iframe').attr('src') != '<?php echo $itemlink; ?>') {
                window.top.$('#modalHolderK2_iframe').attr('src','about:blank');
                window.top.$('#modalHolderK2_iframe').attr('src','<?php echo $itemlink; ?>');
            }
            window.top.$('#modalHolderK2').modal();
            return false;
      });
    });     

It seems that the "window.top.$('#modalHolderK2_iframe').attr('src','about:blank);" is not executed fully before the new src is passed to the iframe.

I guess there is an easy solution but I didnt find anything which worked for me yet.

I just want to avoid the modal to show old content when a new one is called.

like image 629
user1873194 Avatar asked Dec 03 '12 16:12

user1873194


2 Answers

$("#iframe").contents().find("body").html('');

like image 116
techknowfreak Avatar answered Sep 21 '22 16:09

techknowfreak


 $('#iframid').attr('src', '');
like image 20
Satendra Jindal Avatar answered Sep 19 '22 16:09

Satendra Jindal