reptile7's JavaScript blog
Wednesday, September 30, 2009
 
This Window Has No Title, Part 2
Blog Entry #158

Before we get started, and from the In The Name of Completeness Department:

In the first paragraph of the previous post, I said, If you wanted to, say, resize, reshape, reposition, or add some color to the individual chrome bars, neither HTML, CSS, nor JavaScript provides tools for doing so as of this writing - this is not 100% true. Microsoft has implemented a set of eight DHTML properties that can be used to add color to a browser window's scroll bars for MSIE 5.5+ on the Windows platform: scrollbar3dLightColor, scrollbarArrowColor, scrollbarBaseColor, scrollbarDarkShadowColor, scrollbarFaceColor, scrollbarHighlightColor, scrollbarShadowColor, and scrollbarTrackColor. These properties are not 'members' of the window object but are actually CSS extensions whose window-coloring effects are effected when they are applied to the body element. More generally, Microsoft suggests that its scrollbar-color properties can be applied to any element that can give rise to a scrolling mechanism; however, they do not apply to the iframe element.

HTML Goodies' main CSS sector sports a "Scroll Bar Colors" tutorial with a demo page that illustrates all but one of the scrollbar-color properties. (I don't know if any non-MSIE browsers support these properties; I myself don't see any color on Joe's demo page with any of the browsers on my computer. Even as a Mac user, I figured there was a fighting chance that at least Opera would support them: no dice.)

We return now to our discussion of browser window title bars and the visibility thereof. As noted in the last entry, the window object has several Netscape-specific properties corresponding to various window chrome bars; however, it does not have a titlebar property. For secondary windows, JavaScript 1.2 did add a titlebar feature to the window.open( ) method's collection of strWindowFeatures features; the titlebar feature is also supported by MSIE. (Owing to my inability to find specifications for the early versions of JScript, I don't know if Netscape or Microsoft introduced the titlebar feature - it could well have been Microsoft.)

I earlier put Microsoft's titlebar description in front of you; inter alia, it informs us that titlebar is no longer supported by MSIE 5.5+ and is ignored prior to MSIE 5.5. Doesn't sound like such a useful feature, does it? And what does Netscape/Mozilla have to say about titlebar?

In the JavaScript 1.3 Client-Side Reference, the titlebar description reads:

titlebar
(JavaScript 1.2) If yes, creates a window with a title bar. To set the titlebar to no, set this feature in a signed script.

On Mozilla's current window.open( ) page, titlebar is listed in a "Features requiring privileges" subsection, which collects a set of seven features [that] require the UniversalBrowserWrite privilege [to change their default settings], otherwise they will be ignored. Chrome scripts have this privilege automatically, others have to request it from the PrivilegeManager. The titlebar entry therein reads:

titlebar
By default, all new secondary windows have a titlebar. If set to no, this feature removes the titlebar from the new secondary window.
Mozilla and Firefox users can force new windows to always render the titlebar by setting dom.disable_window_open_feature.titlebar to true in about:config or in their user.js file.
Supported in: Netscape 6.x, Netscape 7.x, Mozilla 1.x, Firefox 1.x

Brief commentary on signed scripts, the UniversalBrowserWrite privilege, chrome scripts, and PrivilegeManager

• Signed scripts also date to JavaScript 1.2. Mozilla maintains a "Signed Scripts in Mozilla" document here; several key historical links in this article are dead. "Signing" a script means associating with that script a certificate file that (a) serves as an ID card for the script's author and (b) in effect says, "I wrote this script, which seeks to do something out of the ordinary. Will you kindly grant it permission to do so?" The certificate file itself must be obtained from a certificate authority. Scripts are signed via a command-line program called signtool, which as far as I know is not available for the Macintosh and is thus 'beyond my reach'. The signtool program is documented here; you can download it (more specifically its source code, which you'll have to compile) here if you're using a supported OS and would like to give it a shot.

• The UniversalBrowserWrite privilege is vaguely defined in the "Privileges" subsection of the "Signed Scripts in Mozilla" article; see the subsequent "JavaScript Features Requiring Privileges" subsection for what it will allow you to do.

• Chrome scripts? Mozilla does not explain this term and my attempts to find a meaningful definition therefor elsewhere on the Web have not been successful.

PrivilegeManager is a class belonging to Netscape's custom netscape.security Java package. PrivilegeManager has an enablePrivilege( ) instance method for activating the UniversalBrowserWrite and other privileges via the following syntax:

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");

BTW, the above PrivilegeManager command can be used to write the visible property of the chrome bar objects for a primary browser window that we discussed in the previous entry - see here, for example.

(The PrivilegeManager link on Mozilla's window.open( ) page redirects to the Mozilla Development Center's home page. Strangely, you won't find netscape.security's Javadoc documentation at any of Mozilla's Web sites. My PrivilegeManager link above was fished out of the Internet Archive; also, CardContact currently maintains a netscape.security Javadoc here.)

But here's the kicker: even if you were to go get a certificate file and then do the signtool thing, your titlebar=no script will only work with the Mozilla/Netscape family of browsers. And if MSIE/Safari/Opera* users can't run your script, is it really worth going through all of this? To ask the question is to answer it.
(*Actually, Opera will 'run' the script but will not act on the titlebar feature - vide infra.)

Local experimentation

The "Signed Scripts in Mozilla" article concludes with a broken link to Danny Goodman's dated-but-still-useful "Applying Signed Scripts" article, which can be accessed here, again courtesy of the Internet Archive. Interestingly, "Applying Signed Scripts" contains an "Experimenting Locally Without a Certificate" section that discusses a means of testing support for the UniversalBrowserWrite-requiring strWindowFeatures features without obtaining a certificate file or using signtool; here are its instructions as they apply to Firefox:

(1) Launch Firefox.
(2) Open the about:config pane.
(3) Add a new Boolean signed.applets.codebase_principal_support preference to the about:config pane; set its value to true (if it isn't already true).
(See the "Adding, modifying, and resetting preferences" section of Mozilla's about:config page for how to do this.)
(4) Close the about:config pane.

Seems simple enough to try out, eh? I did the above and then ran the script below with Firefox after also setting the dom.disable_window_open_feature.location, dom.disable_window_open_feature.resizable, and dom.disable_window_open_feature.status preferences in the about:config pane to false:

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
var newWindow = window.open("", "", "height=100,width=100,left=100,top=100,titlebar=no");
netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserWrite");
var newContent = "<html><body style='background-color:red;color:white;'><h3>Hi</h3>";
newContent += "<form style='text-align:center;'><input type='button' value='Ta-ta!'";
newContent += "onclick='self.close( );'></form></body></html>";
newWindow.document.write(newContent);
/* This code is adapted from Example 2 in the "Applying Signed Scripts" article. */


Firefox first unfurled from the top of the Navigation Toolbar the following dialog box:

Firefox's Internet Security confirm dialog

Clicking the button then popped up the newWindow window - look Ma, no chrome! (OK, it's got borders...)

The newWindow window

N.B. With its title bar gone, the newWindow window could not be dragged on the screen.

The script throws a Can't find variable: netscape error when using Safari. More interesting is what happens with Opera. Opera also popped up the newWindow window, but with a title bar, a domain bar, and a resizing grippy; the Opera Java Console, which is accessed via the Advanced submenu of the Tools menu, had a message waiting for me:
Netscape security model is no longer supported. Please migrate to the Java 2 security model instead.
The "Java 2 security model" is documented here for anyone who wishes to pursue this further.

And that wraps up our tour of HTML Goodies' "Opening New Windows With JavaScript" series of tutorials. In the following entry, we'll address a completely different topic in moving to the next "Beyond HTML : JavaScript" tutorial: "The onerror Event Handler".

reptile7

Comments: Post a Comment

<< Home

Powered by Blogger

Actually, reptile7's JavaScript blog is powered by Café La Llave. ;-)