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
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);
4 Comments
Gaurav
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 iframeDenys Séguret
What's your exact goal ? Why do you want to fetch the document only once ?
Gaurav
because i am modifying it on the client side, so for save the change i have to load it only once
Denys Séguret
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.