P
pbd22
hi.
i have spent the past week (i am afraid) trying to get
the below script for uploading files via a hidden iframe
to work.
i have narrowed down my problem to the possibility that
IE doesnt like the fact that the script is instantiating the
object type so many times (of course, tell me if i am wrong).
whatever the case, when i alert the outterHTML of the page,
the <iframe> tag is always empty (no files inside). I'd
really really apprecaite some help here...
i have enclose the problem block in comments below.
thanks.
pbd
<script type="text/javascript">
var IFrameObj; // our IFrame object
function callToServer(theFormName) {
if (!document.createElement) {
return true
};
var IFrameDoc;
var URL = 'set_progress.aspx' + buildQueryString(theFormName);
//FOR ERROR CHECKING - FULL RESPONSETEXT IN NEW WINDOW
//var doc = URL;
// doc=doc.replace(/</g, '<').replace(/\>/g, '>');
//childWin=window.open("", "childwin");
//childWin.document.write("<pre>"+doc+"</pre>");
//childWin.document.close();
if (!IFrameObj && document.createElement) { //1
// create the IFrame and assign a reference to the
// object to our global variable IFrameObj.
// this will only happen the first time
// callToServer() is called
try { //2
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','RSIFrame');
tempIFrame.style.border='0px';
tempIFrame.style.width='0px';
tempIFrame.style.height='0px';
IFrameObj = document.body.appendChild(tempIFrame);
if (document.frames) { //3
// this is for IE5 Mac, because it will only
// allow access to the document object
// of the IFrame if we access it through
// the document.frames array
IFrameObj = document.frames['RSIFrame'];
} // end 3
} // end 2
catch(exception) { // 3
// This is for IE5 PC, which does not allow dynamic creation
// and manipulation of an iframe object. Instead, we'll fake
// it up by creating our own objects.
iframeHTML='\<iframe id="RSIFrame" style="';
iframeHTML+='border:0px;';
iframeHTML+='width:0px;';
iframeHTML+='height:0px;';
iframeHTML+='"><\/iframe>';
document.body.innerHTML+=iframeHTML;
debugger;
//!------------------------- PROBLEM BLOCK
----------------------------------------
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.iframe =
document.getElementById('RSIFrame');
IFrameObj.document.location.replace = function(location) { //4
this.iframe.src = location;
} // end 4
//!------------------------- PROBLEM BLOCK
----------------------------------------
} // end 3
} // end 2
if ((navigator.userAgent.indexOf('Firefox') != -1) &&
(!IFrameObj.contentDocument)) {
// we have to give Firefox 1.5 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer("'+theFormName+'")',50);
return false;
}
if (navigator.userAgent.indexOf('Gecko') !=-1 &&
!IFrameObj.contentDocument) {
// we have to give NS6 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer("'+theFormName+'")',10);
return false;
}
if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
alert("IE5");
IFrameDoc = IFrameObj.document;
} else {
return true;
}
//IFrameDoc.location.replace=URL;
IFrameDoc.location.replace(URL);
return false;
}
function buildQueryString(theFormName) {
var theDIV = document.getElementById('uploadDIV');
var theInputs = theDIV.getElementsByTagName('input');
var qs = '';
for (e=0;e<theInputs.length;e++) {
if (theInputs[e].name!='') {
qs+=(qs=='')?'?':'&'
if (theInputs[e].value != ""){
qs+=theInputs[e].name+'='+escape(theInputs[e].value)
}
}
}
return qs
}
</script>
i have spent the past week (i am afraid) trying to get
the below script for uploading files via a hidden iframe
to work.
i have narrowed down my problem to the possibility that
IE doesnt like the fact that the script is instantiating the
object type so many times (of course, tell me if i am wrong).
whatever the case, when i alert the outterHTML of the page,
the <iframe> tag is always empty (no files inside). I'd
really really apprecaite some help here...
i have enclose the problem block in comments below.
thanks.
pbd
<script type="text/javascript">
var IFrameObj; // our IFrame object
function callToServer(theFormName) {
if (!document.createElement) {
return true
};
var IFrameDoc;
var URL = 'set_progress.aspx' + buildQueryString(theFormName);
//FOR ERROR CHECKING - FULL RESPONSETEXT IN NEW WINDOW
//var doc = URL;
// doc=doc.replace(/</g, '<').replace(/\>/g, '>');
//childWin=window.open("", "childwin");
//childWin.document.write("<pre>"+doc+"</pre>");
//childWin.document.close();
if (!IFrameObj && document.createElement) { //1
// create the IFrame and assign a reference to the
// object to our global variable IFrameObj.
// this will only happen the first time
// callToServer() is called
try { //2
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','RSIFrame');
tempIFrame.style.border='0px';
tempIFrame.style.width='0px';
tempIFrame.style.height='0px';
IFrameObj = document.body.appendChild(tempIFrame);
if (document.frames) { //3
// this is for IE5 Mac, because it will only
// allow access to the document object
// of the IFrame if we access it through
// the document.frames array
IFrameObj = document.frames['RSIFrame'];
} // end 3
} // end 2
catch(exception) { // 3
// This is for IE5 PC, which does not allow dynamic creation
// and manipulation of an iframe object. Instead, we'll fake
// it up by creating our own objects.
iframeHTML='\<iframe id="RSIFrame" style="';
iframeHTML+='border:0px;';
iframeHTML+='width:0px;';
iframeHTML+='height:0px;';
iframeHTML+='"><\/iframe>';
document.body.innerHTML+=iframeHTML;
debugger;
//!------------------------- PROBLEM BLOCK
----------------------------------------
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.iframe =
document.getElementById('RSIFrame');
IFrameObj.document.location.replace = function(location) { //4
this.iframe.src = location;
} // end 4
//!------------------------- PROBLEM BLOCK
----------------------------------------
} // end 3
} // end 2
if ((navigator.userAgent.indexOf('Firefox') != -1) &&
(!IFrameObj.contentDocument)) {
// we have to give Firefox 1.5 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer("'+theFormName+'")',50);
return false;
}
if (navigator.userAgent.indexOf('Gecko') !=-1 &&
!IFrameObj.contentDocument) {
// we have to give NS6 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer("'+theFormName+'")',10);
return false;
}
if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
alert("IE5");
IFrameDoc = IFrameObj.document;
} else {
return true;
}
//IFrameDoc.location.replace=URL;
IFrameDoc.location.replace(URL);
return false;
}
function buildQueryString(theFormName) {
var theDIV = document.getElementById('uploadDIV');
var theInputs = theDIV.getElementsByTagName('input');
var qs = '';
for (e=0;e<theInputs.length;e++) {
if (theInputs[e].name!='') {
qs+=(qs=='')?'?':'&'
if (theInputs[e].value != ""){
qs+=theInputs[e].name+'='+escape(theInputs[e].value)
}
}
}
return qs
}
</script>