| JavaScript & HTML Tips | |||||||||||||||||||||||||||||||||||||||||
| Feature
highlight: Window Interactions Credit: Imagenation Description
myWin = window.open(file_url,
name, window_option_settings); awin
= window.open("", "", "width=200,height=200");
//creates an empty 200xx200 window Now the file name or URL is where the browser will look to find the new window to open as in the case of cwin just above. . However, if the file argument is left blank, " ", then the browser will create an empty window and give it the name supplied in the second argument - as in bwin example. And finally the first case will create a completely empty window. But you can fill it up with content like so: awin.document.write("<html><body><hr>My
Window - Hello World<hr><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-4281076-1");
pageTracker._initData();
pageTracker._trackPageview();
</script><script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-4281076-1");
pageTracker._initData();
pageTracker._trackPageview();
</script></body>,/html>"); The next set of code of interest is what happens in the created window. Three things. First it steals its background color from the Main window. Second it finds the name of the Main window and prints it in a popup. Third it passes input from its window back to the Main Window. Not too shabby. Let see how in reverse order. <INPUT TYPE="text" SIZE=25 onChange="self.opener.document.forms[0].entry.value = this.value"> The critical line is the onChange=... The onChange event gets triggered when an input textfield is changed. But note VB programmers - the event does not get triggered until the input field loses focus(unlike in VB which reacts to every typed in character). Just as important is the one line JavaScript, here is how to interpret that hefty line. self
works like "this" in Java and other languages, it refers to the
window being currently used. But self.opener refers to the window
that opened this one - the parent or Main window. document.forms[0] refers
to the first form in the Main Window (this page, in fact). And entry.value
refers to the name of the inpout text field in this window. So jstagteam.htm
passes a value back to its calling Web page, this page. Now just think of
how this can be generalized. A user fills in a detail form - and then passes
the key fields for display back in the main window. the opportunities for
between page transfer of data are only limited by the lack of support for
a consistent DOM and/or JavaScript model of the document, images, and other
HTML tag elements among the browsers. To
explain thhe second feature, displaying from the 2nd window, the title of
the main window is actually easy to do. Just as before self.opener refers
back to the window that called or opened this one. document.title refers
to the Main window's title - and the alert() just packages it up
in a convenient browser popup message window. Finally here is a summary of the common Windows options that can be set on opening or creating a new window from JavaScript regardless of browser used.
|
|||||||||||||||||||||||||||||||||||||||||
Top of Page Tutorials Home JavaScript References JavaScript Books |
|||||||||||||||||||||||||||||||||||||||||