Home / JavaScript Tutorials / Creating window remote controls/ Part 2 |
|
WA Help
Forum Jump to...
Link
to us!
|
.. The window.opener property of NS 3.x is created whenever a secondary window is opened using the window.open method. Using this opener property, we can access the main window (the default browser window) from the newly opened window. You may have learned from the tutorial Windows and JavaScript how to access a secondary window from the main window, but not the other way around. Lets briefly see what I mean: To open a new window: <script> To access "anotherwindow" from main, we would simply use the keyword "anotherwindow": <script> In the above example, the access between windows using JavaScript is a one way street; we can access properties/methods of the secondary window from the main , but cannot access the properties/methods of the main window from the secondary:
Here's where the window.opener property comes in. By using this property in the secondary window, we have access to the main window as well. Lets implement an example where the secondary window accesses and changes the background color of the main. The below's a secondary window that contains buttons that changes the background color of the main window when clicked on: <!--code for secondary window--> By using the window.opener property, the
secondary window now has access to something it never had- access to its boss, the main
window. If it helps, think
of the window.opener property as JavaScript's way of saying "main window",
or "the window that opened the other window". <!--code for secondary remote control
window--> Wow, a JavaScript remote is sure easier to construct than a real remote! |
. |