Javascript
Jeff Williamson
Northern Virginia Community College
www.nvcc.edu/home/nvwillj/html-graphics/
nvwillj@nvcc.edu
Remote windows
Javascript can open and close new windows, and control one (or more)
windows from another, like a remote control. The opening and closing parts
are easy; the remote control is a bit more difficult.
Open: To open a new window, use this code:
<a
href="origin.html"
onClick="window.open('new_page.html', 'NewWindow','toolbar=yes, location=yes,
directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no,
copyhistory=yes, width=635,height=260')">Display
text</a>
where "origin.html" is the page containing the Javascript,
and "new_page.html" is an existing page that will be loaded
into a new window.
Note 1: I think these are all of the possible attributes. You
can pretty much see how to adjust them - change toolbar=yes to toolbar=no
and your window will be a little smaller, with no toolbar. You can probably
leave stuff out and have it default to normal window attributes, e.g.
omit "status=" and you'll probably get a status bar.
Note 2: All HTML files are the same size, or at least coded
the same. What you change is the size of the window the file displays
in.
Click here
for an example
The bare-bones, if you just want to open a new window with all the default
stuff on, is this:
<a
href="origin.html"
onClick="window.open ('new_page.html')">Display
text</a>
Click here
for an example
Close: Windows are easier to close than open. Of course, the user
can just close Javascript windows the same as any other windows, but it
might help newer uses to have a close button.
Click here
for an example
<form>
<input type="button" value="Eeeeww! - Close this!!" onClick="self.close()">
</form>
Remote control: A remote control is a pop-up window with enough
links and Javascript to control the window that it originated from.
That last part is important; Javascript can determine parent windows
and their children (windows popped up from parent windows), and it can
determine the top most window (sort of like the highest ancestor to
parents and children), but it can't determine, say, window 2 of 5.
I made a remote from my EDIT 772 class; it's on the home
page for the course. Code for it came from WebCoder.
They don't have separate instructions, but their comments in the code
are clear enough.
Note 1: The relationship between remote and originating page
is fragile; if the originating page or the remote is reloaded or closed,
the relationship is broken and the remote no longer works (until the
user closes it and clicks up a new one from the originating page)
Note 2: Remotes might be a little passe; I see that sites which
had them at one time or another dropped them, probably because newer
users lose them under windows and everyone has them fail at some time.
|