Web Analytics Made Easy -
StatCounter Using an iframe instead of call to window.open? - CodingForum


No announcement yet.

Using an iframe instead of call to window.open?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Using an iframe instead of call to window.open?

    I have a project that uses window.open to open a separate window.
    It reason and use is to present a form that can be submitted.
    The reason I am presenting the form in a separate window is
    because I don't want the opening window to reload when the
    form is submitted. It contains user data that needs to be reserved
    and submitting a form synchronously will reload the window.
    Thus the form is submitted from the opened window.
    Between the two windows are callback functions that each
    can call on the other.
    So, if I have a script in the opened window with function named help,
    and the opened windows name in the window.opener is joe
    I can call joe.help() from the parent window.
    Likewise in the opened window I can call functions via window.opener
    in the window calling window.open.

    NOW, having a separate window is a problem due
    to the amount of content it will be asked to display.

    I am wondering if I can use an iframe in the same way?

    I am looking at my copy of Javascript:The Definitive Guide,
    6th ed (O'Reilly) and looking at the client side appendix iframe entry
    and it doesn't list a property for iframe that represents the parent
    window in the same way that window opener does in a separate
    window. That is why I am asking here to see if any one has
    any postitive suggestions.

    Thank you for your time and attention.

  • #2
    The problem with opening a popup window is that it has to be enabled by the user as it will be treated for what it is, a popup. Personally, I prefer to use ajax to send the data to the server and to prevent the user from clicking before the ajax completes, is to create a little 'div' the will cover the whole window with opacity of 0 and remove it once the ajax completes.

    As to your question of using iframe, yes to is possible. See windows.postMessage


    • #3
      Thank you for the response. josephm'
      Many years ago I was using frames. But I have since ditched
      the use of frames. I forgot about the window. parent property.

      I don't use ajax in this situation because it is specifically for
      the creation and testing of forms that will be submitted.

      I have written a module for XMLHttpRequest object (ajax)
      and use it extensively in other projects.

      In this project both the parent window and the file loaded
      into the iframe will be in the same origin, same directory.

      One other question I have regarding Microsoft browsers:
      Are they now completely DOM compatible? I haven't
      been following. I only have code in my ajax module
      for FF/Chrome/Safari etc browsers.

      Thank your for time and attention;


      • #4
        It has been a while since I dropped the idea of supporting IE < 9. IE9 -> edge seems to be allright.

        Any way, these are the problems (as far as I can remember).

        XMLHttpRequest is not supported. The equivalent is ActiveObject('Microsoft.XMLHttp).
        AddEventListener -> attachEvent.
        RemoveEventListener -> detachEvent

        The following might not be supported but you can always do a polyfill.
        • Array.prototype.indexOf
        • Array.prototypes.includes
        • Array.isArray
        • String.prototype.trim
        • String.prototype.indexOf
        • Array.prototype.find
        • String.prototype.toLowerCase
        • String.ptototype.toUpperCase

        No support
        • WebRtc

        Selection manipulation
        • document.selection.createRange -> window.getSelection
        if I remember it right (at least for IE6 (XP)), console.log is not suppported. I abend if you do a console.log.

        Last edited by josephm; Jun 7, 2020, 05:08 AM. Reason: Added more infos