Java Reference
In-Depth Information
</p>
<h4>Professional JavaScript for Web Developers</h4>
<p>
<img src=”pro_js.jpg” alt=”Professional JavaScript, 2nd Edition” border=”0”
onclick=”showDetails('pro_js_details.htm')” />
</p>
Adding HTML to a New Window
You learned earlier that you can pass an empty string as the fi rst parameter of the window object's
open() method and then write to the page using HTML. Let's see how you would do that.
First, you need to open a blank window by passing an empty value to the fi rst parameter that specifi es
the fi le name to load.
var newWindow = window.open(“”,”myNewWindow”,”width=150,height=150”);
Now you can open the window's document to receive your HTML.
newWindow.document.open();
This is not essential when a new window is opened, because the page is blank; but with a document
that already contains HTML, it has the effect of clearing out all existing HTML and blanking the page,
making it ready for writing.
Now you can write out any valid HTML using the document.write() method.
newWindow.document.write(“<h4>Hello</h4>”);
newWindow.document.write(“<p>Welcome to my new little window</p>”);
Each time you use the write() method, the text is added to what's already there until you use the
document.close() method.
newWindow.document.close();
If you then use the document.write() method again, the text passed will replace existing HTML
rather than adding to it.
Adding Features to Your Windows
As you have seen, the window.open() method takes three parameters, and it's the third of these param-
eters that you'll be looking at in this section. Using this third parameter, you can control things such
as the size of the new window created, its start position on the screen, whether the user can resize it,
whether it has a toolbar, and so on.
Search WWH ::




Custom Search