|
The third argument of the window.open() method is a comma-separated list of window features, specified as a single string (enclosed in a single pair of quotes). (Be careful not to specify each feature as an independent argument of the window.open() method.) If you omit the window.open() method’s third argument, the window features default to those of a new window manually opened from the browser’s File menu. Any specification for the third argument value, including an empty string, turns off all unspecified attributes of the new window. Table 27-1 lists all window attributes you can control: Table 27-1. The window.open() method attributes.
As is obvious from these major differences, Microsoft Internet Explorer and Netscape Navigator are designed differently. Here are a few minor distinctions:
As menu bars are foreign to the Macintosh OS, the menubar option is not supported by browser windows on the Mac. The attribute copyhistory is omitted from Table 27-1 because it is buggy and tends not to work on some browser-platform combinations. This attribute specifies if the originating window’s history list should be copied to the new window. If not specified, the history list of the new window starts from scratch. As emphasized above, the third argument of the window.open() method is a single string. A call to this function can look like this:
var remote = open("http://www.yahoo.com", "win1", "height=300,width=400,toolbar")
First, notice that there are no spaces between the attributes. Then, be aware that there are basically three ways to specify a value for a Boolean attribute (all attributes except for the window’s height and width):
You can use the window.open() method to create a customized alert box, for example. Example 27-1 shows a general function for this purpose.
<HTML> <HEAD> <TITLE>A custom "alert"</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function pop(height, width, content) { win = window.open("", "", "height=" + height + ",width=" + width) if (win != null) { win.document.open('text/html') win.document.write("<HTML><HEAD >;TITLE>JavaScriptAlert </TITLE></HEAD><BODY>") win.document.write(content) win.document.write("</BODY></HTML>") win.document.close() } } // --> </SCRIPT> </HEAD> <BODY> <FORM> <INPUT TYPE="button" VALUE="custom alert"onClick="pop(75,250,'You can use such windows instead of alert dialog boxes!')"> </FORM> </BODY> </HTML>
Example 27-1. A small window can replace the classic alert dialog box. This alternative to the built-in window.alert() method gives you a way to get rid of the annoying “JavaScript Alert:” message under Netscape Navigator, to size the window as you like, and to display images in the window. Later in this chapter, we show how to keep the window in front of other ones and how to implement an OK button for closing the window. Figures 27-4 and 27-5 show the windows generated by Example 27-1 under Navigator and IE, respectively. An IE 3.0x Bug WorkaroundA very bizarre bug in Internet Eplorer 3.0x is that it does not like assigning the document object to a variable before invoking its methods. the following script, for example, should be equivalent to Example 27-1, but fails to work properly (the window opens but nothing is written to it):
<HTML> <HEAD> <TITLE> A custom "alert" </TITLE> <SCRIPT LANGUAGE="JavaScript> <!-- function pop(height, width, content) { win = window,open(("","","height=" + height + ",width=" + width) if (win I = null) { doc = win,document doc,open('text/html') doc.write("<HTML><HEAD><TITLE>JavaScript Alert </TITLE></HEAD><BODY>") doc.write(content) doc.write("</BODY></HTML>") doc.close() } } // --> <SCRIPT> <HEAD> <BODY> <FORM> <INPUT TYPE="button"VALUE="custom alert" onClick="pop(75, 250, 'You can use such windows instead of alert dialog boxes!')"> </FORM> </BODY> </HTML>
The workaround to this problem is not to design the document object to a local variable before invoking its methods.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
With any suggestions or questions please feel free to contact us |