IFrame.onload, IE and Remote Scripting

T

Tom Cole

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

ASM

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)
 
T

Tom Cole

Tom Cole a écrit :










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

Marc

So how can RPC to another domain be done?

On the server.

(sorry for the 'top' post)

Tom Cole a écrit :



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

Tom Cole

On the server.

Fair enough.
(sorry for the 'top' post)






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.





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.




Thanks.

<snip>- Hide quoted text -

- Show quoted text -
 
A

ASM

Tom Cole a écrit :
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. :)
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).
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top