Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Thanked 0 Times in 0 Posts

    Iframe and JS objects

    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,


  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts

    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.
    Be yourself. No one else is as qualified.

  3. #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 626 Times in 605 Posts
    note that because constructors are defined on window, custom objects lose their prototype members when transferring windows.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts