really having a tough time with hidden iframes.

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, '&lt;').replace(/\>/g, '&gt;');
//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>
 
V

VK

pbd22 said:
i have spent the past week (i am afraid) trying to get
the below script for uploading files via a hidden iframe
to work.

Not sure what do you mean by "uploading files". If you mean files from
local drive then you can do it using type="file" controls only (given
the standard security settings). So you can spend another week or year
for that with no luck.
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).

Even 10,000 new javascript Object would not make a difference. So
something other is going on. To submit a form while staying on the same
page you can use form target attribute. Also an ajaxoid will work for
you as well (unless you have type="file" controls in your form).
 
P

pbd22

Jim -

I "did" do exactly what you are saying. If you re-read my post,
I mention that there is a block inside my script where the Object
class is reinstantiated multiple times and i am wondering if this
could cause my script to fail. I posted the whole script
and enclosed the problem block in the below comments.

//---------PROBLEM BLOCK---------------

I included the whole script because I may be wrong in assuming
that my particular diagnosis of the problem is the correct one.
providing just a small hunk of code doesn't leave much room for
analysis.

But, if people don't take time to read the post, maybe i'll do as you
say and provide more code as questions come up. whatever leads
to the solution.

thanks.

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.
[snip]

"I have a large script that doesn't work!" is a familiar situation. The
way to tackle it is to pare down the script until you have the smallest
script that still displays the unwanted behavior. Post _that_ script.
 
P

pbd22

VK -

thanks. yes, i am uploading from a hard drive to a remote destination
drive.
i am indeed using type=file and feel pretty confident that i have the
relevant
attributes correct in my upload form (type=file,
enctype=multipart/data-form, etc).
Even 10,000 new javascript Object would not make a difference. So
something other is going on. To submit a form while staying on the same
page you can use form target attribute. Also an ajaxoid will work for
you as well (unless you have type="file" controls in your form).

thanks for responding to my posted question. I cannot use ajax because
i do
have type="file". if you are telling me that the amount of Object
declarations
makes no difference, then something else is causing it to fail. below
is my
form tag:

<form id="uploadForm" method="post" enctype="multipart/form-data"
action="set_progress.aspx" onsubmit="return callToServer(this.id)">

the form "does" submit, the problem is that the <iframe> </iframe> tags
don't
submit with innerHTML content (the uploaded files). if i take out the
onsubmit="return callToServer(this.id)" attribute from the form tag,
the form submits just fine and
the files are read by the server. but, i lose the "fake ajax" feel to
the upload.

so, for some reason, the uploaded files are not making it into the
hidden iframe
and i can't figure this out. i don't think the target attribute is the
answer but,
just in case, how would you suggest that i use it?

thanks a ton for your help.
 
V

VK

pbd22 said:
submit with innerHTML content (the uploaded files).

This doesn't have sense. You cannot get the content of uploaded files
by any means. The only thing you can do - sometimes - is to read the
file name - but without path part - by using inputFileControl.value

You can make you server-side script echoing received data - if they are
textual - back to some (i)frame but for this you still have to submit
all data to the server first. If you are doing this or if you simply
want to stay on the current page after submission then you don't need
any script at all - expecially such complicated one.

<iframe name="output" src="aBlankPage.html" width="468"
height="60"></iframe>
<form method="post" action="your.cgi" enctype="multipart/form-data"
target="output">
<input type="file" name="file">
</form>
 
P

pbd22

VK -

thanks for your reply. it was very helpful. i did as you suggest and
took out the complicated
script altogether and used the target attribute. this seems to work -
the iframe does pass
a input string that is caught by the server. however, the string that
is being passed isn't what i
am expecting (the server-side count is &H0, &H1, &H2, etc) and i am
wondering why that
is. do you know how to capture the string being passed to the server
via iframe? I have tried
the tricks i know - alert on the client, requesting the absoluteuri on
the server - but they don't work.

thanks again.
Jim said:
38g2000cwa.googlegroups.com:


i have spent the past week (i am afraid) trying to get
the below script for uploading files via a hidden iframe
to work.

[snip]

"I have a large script that doesn't work!" is a familiar situation.
The way to tackle it is to pare down the script until you have the
smallest script that still displays the unwanted behavior. Post
_that_ script.

I "did" do exactly what you are saying. If you re-read my post,
I mention that there is a block inside my script where the Object
class is reinstantiated multiple times and i am wondering if this
could cause my script to fail. I posted the whole script
and enclosed the problem block in the below comments.

You have a big script and you don't know why it doesn't do what you
want. So you posted the whole script and asked, Do you think it might be
here?

Now, here is how to tackle a problem like this. You are not helpless!
You can do your own investigation! Really!

Copy the script to a new file, which you can experiment with, without
touching the original. Start deleting lines of code and running the
scrfpt to observe the behavior, to be sure it still doesn't do what you
want.

Eventually you will be down to a minimum number of lines of code that
still misbehave in exactly the same way your whole script misbehaves.
You will have isolated the problem to those lines of code. Look at them
to see if you can figure out why they don't work. If not, post just
those few ines of code, and ask for help with them. (And quit
top-posting. It isn't polite.)
 
P

pbd22

VK -

for what it is worth, i found an explaination as to why I was using the
complicated script in preference to the solution using the target
attribute:

"But you've probably already realized that there are some serious
problems with this simplest of remote scripting scenarios. Perhaps most
seriously, this method renders the "back" and "reload" buttons in most
browsers useless. Because the loading of server.html in the IFRAME is
added to the browsers history object, hitting the reload button after
you've loaded server.html, for instance, reloads server.html in the
IFRAME instead of reloading client.html as would be expected.

NOTE: You may or not experience this problem, depending on a
combination of factors including your browser version, server platform,
http headers, and browser settings. But trust me, if you simply target
a link at an IFRAME, you will have users that have problems with their
reload and back buttons."
VK -

thanks for your reply. it was very helpful. i did as you suggest and
took out the complicated
script altogether and used the target attribute. this seems to work -
the iframe does pass
a input string that is caught by the server. however, the string that
is being passed isn't what i
am expecting (the server-side count is &H0, &H1, &H2, etc) and i am
wondering why that
is. do you know how to capture the string being passed to the server
via iframe? I have tried
the tricks i know - alert on the client, requesting the absoluteuri on
the server - but they don't work.

thanks again.
Jim Land (NO SPAM) wrote:
38g2000cwa.googlegroups.com:


i have spent the past week (i am afraid) trying to get
the below script for uploading files via a hidden iframe
to work.

[snip]

"I have a large script that doesn't work!" is a familiar situation.
The way to tackle it is to pare down the script until you have the
smallest script that still displays the unwanted behavior. Post
_that_ script.
I "did" do exactly what you are saying. If you re-read my post,
I mention that there is a block inside my script where the Object
class is reinstantiated multiple times and i am wondering if this
could cause my script to fail. I posted the whole script
and enclosed the problem block in the below comments.

You have a big script and you don't know why it doesn't do what you
want. So you posted the whole script and asked, Do you think it might be
here?

Now, here is how to tackle a problem like this. You are not helpless!
You can do your own investigation! Really!

Copy the script to a new file, which you can experiment with, without
touching the original. Start deleting lines of code and running the
scrfpt to observe the behavior, to be sure it still doesn't do what you
want.

Eventually you will be down to a minimum number of lines of code that
still misbehave in exactly the same way your whole script misbehaves.
You will have isolated the problem to those lines of code. Look at them
to see if you can figure out why they don't work. If not, post just
those few ines of code, and ask for help with them. (And quit
top-posting. It isn't polite.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top