How can I reload an iframe on click?

19,663

Solution 1

like this

document.getElementById('iframeID').contentWindow.location.reload();

or via

document.getElementById('iframeID').src = document.getElementById('iframeID').src;

Solution 2

    $("#reload").click(function() {
        jQuery.each($("iframe"), function() {
            $(this).attr({
                src: $(this).attr("src")
            });
        });
        return false;
    });

This above code will reload every iframe in your page, every time the link with id=reload is clicked

Thanks to @Haim Evgi

Or you can do the same also like this

$('iframe').each(function() {
  this.contentWindow.location.reload(true);
});

Solution 3

You can do something like this:

$("#iframe").attr('src', ($('#iframe').attr('src'));

Solution 4

var iframe = document.getElementById('ID');

iframe.src = iframe.src;
Share:
19,663
Krishna Kumar
Author by

Krishna Kumar

JavaScript | Node | Angular Developer Email: [email protected]

Updated on June 05, 2022

Comments

  • Krishna Kumar
    Krishna Kumar almost 2 years

    Possible Duplicate:
    Reload an iframe with jQuery

    How can I cause an <iframe> to reload on a click event?

    I tried this, but it is not working:

    jQuery("#link").click(function(){
       jQuery('#iframeID')[0].reload();
    })
    
  • JMarsh
    JMarsh over 7 years
    Thanks for this, very helpful to append a 'reload' class to all my modals with videos within and this handles them all perfectly.