* sort Used to order an array of integers in ascending order (O(n)).
                     * @param {Array} arr
                     * @return {Promise}
                    function sort (arr) {
                        return new Promise(resolve => {
                            const sorted = [];
                            for (const item of arr) {
                                setTimeout(item => sorted.push(item), item, item);
                            setTimeout(() => resolve(sorted), arr.reduce((a, b) => a + b, 0) + 1);
                    «Nullam elementum blandit molestie.
                    Aenean condimentum lectus ut felis.
                    Phasellus fringilla nisl tincidunt dolor.»
                    «Nam quis ante sed neque rhoncus.
                    Proin porta, turpis quis iaculis.
                    Maecenas tristique vulputate magna, vel laoreet.»
                    «Nullam lobortis turpis a tempor molestie.
                    Maecenas fringilla nisl at malesuada porta.»
07/22/2019, Vasile Pește

How to reload an iframe in JavaScript

Sometimes might happen that we need to reload an iframe but what is the cross browser solution? Let’s see together how to reload an iframe with just one line of JavaScript code.

How to reload an iframe

This is a personal approach on how to reload an iframe, thought because the other available solutions didn’t always work and needed specific code for specific browsers.

// Used as reference to the iframe node.
var iframe = window.document.getElementById("iframe");

// Used to reload the iframe.
iframe.parentNode.replaceChild(iframe.cloneNode(), iframe);

There are many solutions on how to reload an iframe using JavaScript but certainly this is the best approach if you want to refresh an iframe without having to deal with browser compatibility.


Together we have seen how to refresh an iframe in JavaScript using a cross browser solution. Hope it helps!