Creating window remotes using a user defined property
Many people think that the only way for a pop up window to reference the
main window that opened it is via the "
window.opener" property. This turns
out to be untrue. An alternate method is to create a
custom property that "simulates" the window.opener property. There's no
real advantage to using this technique over "window.opener" except to
Lets walk through this process one step at a time. To begin with, we will first implement our custom property in the main window:
The core of the above is:
"creator" is a custom property added to "win2" that acts as the opener property. We could have called "creator" some other name, if we wanted to. "self", however, is a pre-built property, and has to be called as such. This property references the current window, and by assigning the current window (the main window, in this case) to the creator property, we have our own window.opener property!
All we have to do now is use this custom property in the document inside the remote control window to access the main window:
Ok, so we've went over the two techniques for creating window remotes.
- Tutorial introduction
- Creating window remotes using the window.opener property
- Creating window remotes using a user defined property