IFrame.onload, IE and Remote Scripting

Discussion in 'Javascript' started by Tom Cole, Mar 23, 2007.

  1. Tom Cole

    Tom Cole Guest

    IFrames have been used by years for people to accomplish many of the
    tasks the XMLHttpRequest does for them now...I unfortunately am late
    in the game and XMLHttpRequest was already out there by the time I got
    serious about using Javascript for more than just rollover images...

    I now would like to learn about the concept for the purposes of
    creating Ajax-like requests across domains.

    I felt like I had the basic concept down, but am running into a few
    issues I'd like the experts to help me with...

    First I am trying to perform all this as a .js file without any
    requirements from the end-user (i.e. they don't have to create an
    iframe in their document OR they won't have to specify an onload
    handler in their server response)...and there I am creating the iframe
    programmatically using this:

    iframe = document.createElement('IFRAME');
    iframe.width = 0;
    iframe.height = 0;
    iframe.style.border = 'none';
    iframe.id = "internal_frame";
    iframe.name = "internal_frame";
    iframe.src= "blank.html";
    iframe.onload = function() { alert('Something'); };
    document.body.appendChild(iframe);

    I then load cross-domain requests by setting the src attribute of the
    iframe. In opera and FF, I get my little alert box, so I'm good to go
    and read the iframe's contents... But in IE, I do not get an alert
    box. Therefore I don't know how to be alerted when the load is
    complete so the rest of my code can go and read the contents.

    Second of all...what is the best way to obtain the contents of the
    iframe (the server response) from the onload event handling function?

    I'm sorry if this is so old school, it's just very new to me.
     
    Tom Cole, Mar 23, 2007
    #1
    1. Advertising

  2. Tom Cole

    ASM Guest

    Tom Cole a écrit :
    >
    > and there I am creating the iframe
    > programmatically using this:
    >
    > iframe = document.createElement('IFRAME');
    > iframe.width = 0;
    > iframe.height = 0;
    > iframe.style.border = 'none';
    > iframe.id = "internal_frame";
    > iframe.name = "internal_frame";
    > iframe.src= "blank.html";
    > iframe.onload = function() { alert('Something'); };
    > document.body.appendChild(iframe);
    >
    > I then load cross-domain requests by setting the src attribute of the
    > iframe. In opera and FF, I get my little alert box, so I'm good to go
    > and read the iframe's contents... But in IE, I do not get an alert
    > box.


    With IE do you get the new file in your iframe ?

    Probably better result with :
    parent.internal_iframe.location = 'my_new_file.htm';
    than using setAttribute();

    > Second of all...what is the best way to obtain the contents of the
    > iframe (the server response) from the onload event handling function?


    I'am not very sure you'll be authorized to get the content of the iframe ...
    especially if this content comes from another domain.


    nota :
    You can also use an 'object' insteed of an 'iframe' to include some html
    file.
    (with much more restrictions about cross domain)


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Mar 23, 2007
    #2
    1. Advertising

  3. Tom Cole

    Tom Cole Guest

    On Mar 23, 6:10 pm, ASM <>
    wrote:
    > Tom Cole a écrit :
    >
    >
    >
    >
    >
    >
    >
    > > and there I am creating the iframe
    > > programmatically using this:

    >
    > > iframe = document.createElement('IFRAME');
    > > iframe.width = 0;
    > > iframe.height = 0;
    > > iframe.style.border = 'none';
    > > iframe.id = "internal_frame";
    > > iframe.name = "internal_frame";
    > > iframe.src= "blank.html";
    > > iframe.onload = function() { alert('Something'); };
    > > document.body.appendChild(iframe);

    >
    > > I then load cross-domain requests by setting the src attribute of the
    > > iframe. In opera and FF, I get my little alert box, so I'm good to go
    > > and read the iframe's contents... But in IE, I do not get an alert
    > > box.

    >
    > With IE do you get the new file in your iframe ?
    >
    > Probably better result with :
    > parent.internal_iframe.location = 'my_new_file.htm';
    > than using setAttribute();


    I have no problem loading the page(s), the only issue is that the
    function declared in this line:

    iframe.onload = function() { alert('Something'); };

    never gets executed in IE, although it executes perfectly after
    loading in Opera and in Firefox.

    >
    > > Second of all...what is the best way to obtain the contents of the
    > > iframe (the server response) from the onload event handling function?

    >
    > I'am not very sure you'll be authorized to get the content of the iframe ....
    > especially if this content comes from another domain.


    That's what I'm experiencing, I'm getting security exceptions in Opera
    and in Firefox. So how can RPC to another domain be done?

    My situation is that I have one business that is hosting several
    websites with products for specific industries. But at the end of the
    day all the orders are processed the same and arrive in the same
    system. I can reuse the same base of servlets to accept and process
    all the orders without having to concern myself with making sure X
    websites all have the latest version of a servlet.

    >
    > nota :
    > You can also use an 'object' insteed of an 'iframe' to include some html
    > file.
    > (with much more restrictions about cross domain)


    Thanks.

    >
    > --
    > Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    > Stephane Moriaux and his (less) old Mac already out of date- Hide quoted text -
    >
    > - Show quoted text -
     
    Tom Cole, Mar 23, 2007
    #3
  4. Tom Cole

    Marc Guest

    >So how can RPC to another domain be done?

    On the server.

    (sorry for the 'top' post)

    "Tom Cole" <> wrote in message
    news:...
    On Mar 23, 6:10 pm, ASM <>
    wrote:
    > Tom Cole a écrit :
    > > and there I am creating the iframe
    > > programmatically using this:

    >
    > > iframe = document.createElement('IFRAME');
    > > iframe.width = 0;
    > > iframe.height = 0;
    > > iframe.style.border = 'none';
    > > iframe.id = "internal_frame";
    > > iframe.name = "internal_frame";
    > > iframe.src= "blank.html";
    > > iframe.onload = function() { alert('Something'); };
    > > document.body.appendChild(iframe);

    >
    > > I then load cross-domain requests by setting the src attribute of the
    > > iframe. In opera and FF, I get my little alert box, so I'm good to go
    > > and read the iframe's contents... But in IE, I do not get an alert
    > > box.

    >
    > With IE do you get the new file in your iframe ?
    >
    > Probably better result with :
    > parent.internal_iframe.location = 'my_new_file.htm';
    > than using setAttribute();


    I have no problem loading the page(s), the only issue is that the
    function declared in this line:

    iframe.onload = function() { alert('Something'); };

    never gets executed in IE, although it executes perfectly after
    loading in Opera and in Firefox.

    >
    > > Second of all...what is the best way to obtain the contents of the
    > > iframe (the server response) from the onload event handling function?

    >
    > I'am not very sure you'll be authorized to get the content of the iframe
    > ...
    > especially if this content comes from another domain.


    That's what I'm experiencing, I'm getting security exceptions in Opera
    and in Firefox. So how can RPC to another domain be done?

    My situation is that I have one business that is hosting several
    websites with products for specific industries. But at the end of the
    day all the orders are processed the same and arrive in the same
    system. I can reuse the same base of servlets to accept and process
    all the orders without having to concern myself with making sure X
    websites all have the latest version of a servlet.
    >
    > nota :
    > You can also use an 'object' insteed of an 'iframe' to include some html
    > file.
    > (with much more restrictions about cross domain)


    Thanks.

    <snip>
     
    Marc, Mar 23, 2007
    #4
  5. Tom Cole

    Tom Cole Guest

    On Mar 23, 6:40 pm, "Marc" <> wrote:
    > >So how can RPC to another domain be done?

    >
    > On the server.


    Fair enough.

    >
    > (sorry for the 'top' post)
    >
    > "Tom Cole" <> wrote in message
    >
    > news:...
    > On Mar 23, 6:10 pm, ASM <>
    > wrote:
    >
    >
    >
    >
    >
    > > Tom Cole a écrit :
    > > > and there I am creating the iframe
    > > > programmatically using this:

    >
    > > > iframe = document.createElement('IFRAME');
    > > > iframe.width = 0;
    > > > iframe.height = 0;
    > > > iframe.style.border = 'none';
    > > > iframe.id = "internal_frame";
    > > > iframe.name = "internal_frame";
    > > > iframe.src= "blank.html";
    > > > iframe.onload = function() { alert('Something'); };
    > > > document.body.appendChild(iframe);

    >
    > > > I then load cross-domain requests by setting the src attribute of the
    > > > iframe. In opera and FF, I get my little alert box, so I'm good to go
    > > > and read the iframe's contents... But in IE, I do not get an alert
    > > > box.

    >
    > > With IE do you get the new file in your iframe ?

    >
    > > Probably better result with :
    > > parent.internal_iframe.location = 'my_new_file.htm';
    > > than using setAttribute();

    >
    > I have no problem loading the page(s), the only issue is that the
    > function declared in this line:
    >
    > iframe.onload = function() { alert('Something'); };
    >
    > never gets executed in IE, although it executes perfectly after
    > loading in Opera and in Firefox.
    >
    >
    >
    > > > Second of all...what is the best way to obtain the contents of the
    > > > iframe (the server response) from the onload event handling function?

    >
    > > I'am not very sure you'll be authorized to get the content of the iframe
    > > ...
    > > especially if this content comes from another domain.

    >
    > That's what I'm experiencing, I'm getting security exceptions in Opera
    > and in Firefox. So how can RPC to another domain be done?
    >
    > My situation is that I have one business that is hosting several
    > websites with products for specific industries. But at the end of the
    > day all the orders are processed the same and arrive in the same
    > system. I can reuse the same base of servlets to accept and process
    > all the orders without having to concern myself with making sure X
    > websites all have the latest version of a servlet.
    >
    >
    >
    > > nota :
    > > You can also use an 'object' insteed of an 'iframe' to include some html
    > > file.
    > > (with much more restrictions about cross domain)

    >
    > Thanks.
    >
    > <snip>- Hide quoted text -
    >
    > - Show quoted text -
     
    Tom Cole, Mar 23, 2007
    #5
  6. Tom Cole

    ASM Guest

    Tom Cole a écrit :
    > On Mar 23, 6:10 pm, ASM <>
    > wrote:
    >> With IE do you get the new file in your iframe ?
    >>
    >> Probably better result with :
    >> parent.internal_iframe.location = 'my_new_file.htm';
    >> than using setAttribute();

    >
    > I have no problem loading the page(s), the only issue is that the
    > function declared in this line:
    >
    > iframe.onload = function() { alert('Something'); };


    and ... did you try the foo.location.href way ?

    (setting attribute is it really same as downloading ?)

    > never gets executed in IE,


    most of the time old JS is better digested by IE

    > although it executes perfectly after
    > loading in Opera and in Firefox.


    he oui ! they are serious browsers. :)

    >> I'am not very sure you'll be authorized to get the content of the iframe ...
    >> especially if this content comes from another domain.

    >
    > That's what I'm experiencing, I'm getting security exceptions in Opera
    > and in Firefox. So how can RPC to another domain be done?


    I think you'l have to get it via server side code.
    It's the same problem with XMLHttpRequest (Ajax).

    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Mar 23, 2007
    #6
  7. Tom Cole

    ASM Guest

    Tom Cole a écrit :
    > On Mar 23, 6:40 pm, "Marc" <> wrote:
    >>> So how can RPC to another domain be done?

    >> On the server.

    >
    > Fair enough.


    not so much ...

    parent.internal_iframe.location = 'server_one.php';

    with file 'server_one.php' :

    <?
    readfile('http://www.server_one.com/folder/file.htm');
    ?>


    or

    parent.internal_iframe.location='servers.php?url=server_one.com/folder/file.htm';

    with file 'servers.php' :

    <?
    readfile('http://www.'.$_GET['url']);
    ?>


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
     
    ASM, Mar 24, 2007
    #7
  8. On Mar 23, 4:23 pm, "Tom Cole" <> wrote:

    > > I'am not very sure you'll be authorized to get the content of the iframe ...
    > > especially if this content comes from another domain.

    >
    > That's what I'm experiencing, I'm getting security exceptions in Opera
    > and in Firefox. So how can RPC to another domain be done?


    see if these help-
    http://www.whatwg.org/specs/web-apps/current-work/#crossDocumentMessages
    http://virtuelvis.com/archives/2005/12/cross-document-messaging

    http://blog.monstuff.com/archives/000304.html
     
    scripts.contact, Mar 24, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabio R.
    Replies:
    0
    Views:
    803
    Fabio R.
    Mar 25, 2005
  2. Daedalous
    Replies:
    3
    Views:
    714
    Daedalous
    Jan 16, 2004
  3. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    559
    Martin Honnen
    Nov 4, 2004
  4. Replies:
    5
    Views:
    264
    Thomas 'PointedEars' Lahn
    May 15, 2005
  5. marco

    onload -->* no onload

    marco, Jun 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    207
    marco
    Jun 24, 2006
Loading...

Share This Page