...

View Full Version : Iframe and JS objects



nakoned
07-21-2010, 04:12 PM
Hi there,
I have a very strange issue using dynamic scripting and iframe. It looks like when when iframe is loaded (i.e. onload method is triggered) all js objects that were sent to iframe before disappear? To clarify... I set iframe.scr from java script that caused it to connect to the server. After connection is established I start sending JS code to it (including some JS objects). At some point connection to iframe is closed (and onload method is called). Later on I reconnect (i.e. set src property again), and try to issue method calls on the JS objects that were sent in earlier session. None of these methods get triggered. Did anyone experienced similar problems? Is there a workaround? (I.e. is there any way I can send register JS Objects globally when sent through iframe?).

Thanks for all your help,

Ed

Old Pedant
07-21-2010, 08:50 PM
No.

Changing the .src of an <iframe> is *NO DIFFERENT* than loading a brand new HTML page into the main window.

It *COMPLETELY* wipes out *EVERYTHING* in the window/iframe and replaces it with the new HTML source.

That of course includes all JavaScript.

In other words, it is no different than doing

location.href = "someNewPage.html";

and expecting the JS objects on the page to remain in memory. They won't. Period.

This is, essentially, what AJAX was created for: To allow changes to a page's contents without affecting what already exists except as dictated by the JS code.

rnd me
07-22-2010, 04:01 AM
note that because constructors are defined on window, custom objects lose their prototype members when transferring windows.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum