Active Client Pages: DOM Roots of the Window Phase
In this tenth part of a twelve-part series on Chrys's approach to Active Client Pages, we look at the factors that gave rise to the window phase. If you want to better understand this technology that allows your web pages to at least appear to load more quickly for your visitors, keep reading.
Active Client Pages: DOM Roots of the Window Phase - How do I send content to a newly-opened window from the parent window? (Page 5 of 5 )
When a window is newly opened, as we have been doing, you can consider it to have one document, which does not have any HTML tags. You have to send in the HTML tags. You do this by using the write() method of the document object of the newly-opened window. While you are at the parent window code, you have to precede "document" with the reference of the newly-opened window. The following code illustrates all of this:
In the script, you have a string, which will be the HTML contents of the opened page. The string has everything, beginning from the start HTML tag, <html> to the end HTML tag, </html>. The penultimate line in the script opens the new window, and the last line does the writing.
Can I set the title of the opened window?
There is no official DOM method for setting the title. While opening the window from the parent window, you should have the title element and its content as part of the string for the write() method.
If so, can I then read the title?
Yes. The document object has a title property. Let us look at this property.
Document title Property
Definition and Usage
The title property returns the title of the current document (the text inside the HTML title element).
Syntax
document.title
Example
<html>
<head>
<title>My title</title>
</head>
<body>
The title of the document is:
<script type="text/javascript">
document.write(document.title)
</script>
</body>
</html>
The definition and usage above is what we get from the specification. It says that the property returns the title of the current document. Well, from my experience, while you are at a different window, if you precede "document" with a reference to a particular window, you will get the title of the window. In the code (example) before the above, adding the following line at the end of the script will return (alert) the title of the child window to the parent window.
alert(myWindow.document.title);
Can I give color to any HTML element in the opened window?
Yes. Include the style attribute or property in the string argument (winStr above) for the write() method.
Can I change the color of the Scroll Bars?
The DOM specification does not give us the feature to do that. However, some browsers have ways you can do that. In your own project, you may have to write a specific code to achieve this for each browser. I do not want this series to be too long, so I will not address that here.
Many questions have been asked and answered. Let us rest now and continue in the next part of the series.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.