RicH and FamouS

       Home         Glosar IT                                                                                                                                                                                                              SUBSCRIBE NOW!
        

09.04.2009

Submit-area unui FORM intr-un IFRAME

Submit-area unui FORM intr-un IFRAME generat dinamic (DOM)
In cazul in care un FORM, contine elemente de tip file, acest FORM nu poate fi submit-at prin AJAX ci intr-un IFRAME, generat dinamic, ascuns. Toate bune si frumoase in FireFox si Opera dar in Internet Explorer, rezultatul submit-arii formului era deschis intr-o noua fereastra!

Pentru a face ca sin in IE, submit-area sa se produca in acest IFRAME generat dinamic, solutia e data in urmatoarea bucata de cod:

Cod:
var iFrameID = 'ID1';
var myIFrame = document.createElement('iframe');
myIFrame.setAttribute('src', 'about:blank');
myIFrame.setAttribute('id', iFrameID);
myIFrame.setAttribute('NAME', iFrameID);
myIFrame.style.display = 'none';
document.body.appendChild(myIFrame);
if((onReadyFunction) && (typeof(onReadyFunction) ==
'function')) captureEvent('load', function(){ var iFrame =
document.getElementById(iFrameID); var doc =
(iFrame.contentDocument)?(iFrame.contentDocument):((iFrame.contentWindow)?(iFrame.contentWindow.document):(self.frames[iFrameID].document));
if (doc.location.href == 'about:blank') { return; } else {
onReadyFunction(doc.body.innerHTML); } }, myIFrame);
if(self.frames[iFrameID].name != iFrameID) { /* *** IMPORTANT: This is
a BUG FIX for Internet Explorer *** */ self.frames[iFrameID].name =
iFrameID; }

Dupa ce IFRAME-ul este creeat, trebuie verificat daca self.frames[iFrameID].name este egal cu iFrameID

    Blog din Moldova    FastCounter 

 
Copyright © 2008-2010 Foster1. All rights reserved.