0

I have one Iframe in my website.I initialized it src at document.ready event. I placed iframe inside the jquery UI dialog, now every time when we open the dialog, Iframe load its contents, but i want that this loading process happens only once at document.ready.Is this possible?

1 Answer 1

1

Yes, you can fetch once the content using an XmlHttpRequest, store it into a local variable and reuse this variable when you open the dialog.

var myReusableContent;

$(window).ready(function() {
    var httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange = function() {
        if (httpRequest.readyState === 4) {
            if (httpRequest.status === 200) {
                myReusableContent = httpRequest.responseText;
            }
        }
    };
    httpRequest.open('GET', muurl);
    httpRequest.send();
});

When you need to fill the iframe, simply do

$('myIframe').html(myReusableContent);
Sign up to request clarification or add additional context in comments.

4 Comments

In my case i cant use $('myIframe').html(myReusableContent); this to fill the iframe because the document which i am loading have some script which conflicts with the iframe parent document, so is there any other way to fill the iframe
What's your exact goal ? Why do you want to fetch the document only once ?
because i am modifying it on the client side, so for save the change i have to load it only once
I suggest you use an ajax logic : fetch data (in json for example), store those data in js variable, and build the html using the data.

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.