really having a tough time with hidden iframes.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pbd22

    really having a tough time with hidden iframes.


    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 <iframetag 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(th eFormName) {

    if (!document.crea teElement) {
    return true
    };

    var IFrameDoc;

    var URL = 'set_progress.a spx' + buildQueryStrin g(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.docume nt.write("<pre> "+doc+"</pre>");
    //childWin.docume nt.close();

    if (!IFrameObj && document.create Element) { //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=docu ment.createElem ent('iframe');
    tempIFrame.setA ttribute('id',' RSIFrame');
    tempIFrame.styl e.border='0px';
    tempIFrame.styl e.width='0px';
    tempIFrame.styl e.height='0px';
    IFrameObj = document.body.a ppendChild(temp IFrame);
    if (document.frame s) { //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='\<i frame id="RSIFrame" style="';
    iframeHTML+='bo rder:0px;';
    iframeHTML+='wi dth:0px;';
    iframeHTML+='he ight:0px;';
    iframeHTML+='"> <\/iframe>';
    document.body.i nnerHTML+=ifram eHTML;
    debugger;
    //!------------------------- PROBLEM BLOCK
    ----------------------------------------
    IFrameObj = new Object();
    IFrameObj.docum ent = new Object();
    IFrameObj.docum ent.location = new Object();
    IFrameObj.docum ent.location.if rame =
    document.getEle mentById('RSIFr ame');
    IFrameObj.docum ent.location.re place = function(locati on) { //4
    this.iframe.src = location;
    } // end 4
    //!------------------------- PROBLEM BLOCK
    ----------------------------------------
    } // end 3
    } // end 2

    if ((navigator.use rAgent.indexOf( 'Firefox') != -1) &&
    (!IFrameObj.con tentDocument)) {
    // we have to give Firefox 1.5 a fraction of a second
    // to recognize the new IFrame
    setTimeout('cal lToServer("'+th eFormName+'")', 50);
    return false;
    }

    if (navigator.user Agent.indexOf(' Gecko') !=-1 &&
    !IFrameObj.cont entDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('cal lToServer("'+th eFormName+'")', 10);
    return false;
    }

    if (IFrameObj.cont entDocument) {
    // For NS6
    IFrameDoc = IFrameObj.conte ntDocument;
    } else if (IFrameObj.cont entWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.conte ntWindow.docume nt;
    } else if (IFrameObj.docu ment) {
    alert("IE5");
    IFrameDoc = IFrameObj.docum ent;
    } else {
    return true;
    }

    //IFrameDoc.locat ion.replace=URL ;
    IFrameDoc.locat ion.replace(URL );

    return false;

    }

    function buildQueryStrin g(theFormName) {

    var theDIV = document.getEle mentById('uploa dDIV');
    var theInputs = theDIV.getEleme ntsByTagName('i nput');

    var qs = '';

    for (e=0;e<theInput s.length;e++) {

    if (theInputs[e].name!='') {
    qs+=(qs=='')?'? ':'&'
    if (theInputs[e].value != ""){
    qs+=theInputs[e].name+'='+escap e(theInputs[e].value)
    }
    }
    }
    return qs
    }

    </script>

  • Jim Land

    #2
    Re: really having a tough time with hidden iframes.

    "pbd22" <dushkin@gmail. comwrote in news:1168827577 .244298.313920@
    38g2000cwa.goog legroups.com:
    >
    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.

    Comment

    • VK

      #3
      Re: really having a tough time with hidden iframes.


      pbd22 wrote:
      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).

      Comment

      • pbd22

        #4
        Re: really having a tough time with hidden iframes.


        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.


        Jim Land (NO SPAM) wrote:
        "pbd22" <dushkin@gmail. comwrote in news:1168827577 .244298.313920@
        38g2000cwa.goog legroups.com:
        >

        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.

        Comment

        • pbd22

          #5
          Re: really having a tough time with hidden iframes.


          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=multipa rt/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="multip art/form-data"
          action="set_pro gress.aspx" onsubmit="retur n callToServer(th is.id)">

          the form "does" submit, the problem is that the <iframe</iframetags
          don't
          submit with innerHTML content (the uploaded files). if i take out the
          onsubmit="retur n callToServer(th is.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.

          Comment

          • VK

            #6
            Re: really having a tough time with hidden iframes.

            pbd22 wrote:
            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 inputFileContro l.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.cg i" enctype="multip art/form-data"
            target="output" >
            <input type="file" name="file">
            </form>

            Comment

            • Jim Land

              #7
              Re: really having a tough time with hidden iframes.

              "pbd22" <dushkin@gmail. comwrote in
              news:1168884653 .350824.52100@a 75g2000cwd.goog legroups.com:
              Jim Land (NO SPAM) wrote:
              >"pbd22" <dushkin@gmail. comwrote in news:1168827577 .244298.313920@
              >38g2000cwa.goo glegroups.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.)

              Comment

              • pbd22

                #8
                Re: really having a tough time with hidden iframes.


                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:
                "pbd22" <dushkin@gmail. comwrote in
                news:1168884653 .350824.52100@a 75g2000cwd.goog legroups.com:
                >
                Jim Land (NO SPAM) wrote:
                "pbd22" <dushkin@gmail. comwrote in news:1168827577 .244298.313920@
                38g2000cwa.goog legroups.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.)

                Comment

                • pbd22

                  #9
                  Re: really having a tough time with hidden iframes.


                  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."

                  pbd22 wrote:
                  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:
                  "pbd22" <dushkin@gmail. comwrote in
                  news:1168884653 .350824.52100@a 75g2000cwd.goog legroups.com:
                  Jim Land (NO SPAM) wrote:
                  >"pbd22" <dushkin@gmail. comwrote in news:1168827577 .244298.313920@
                  >38g2000cwa.goo glegroups.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.)

                  Comment

                  Working...