Appendix D
Current Bugs and Future Enhancements
CONTENTS
This appendix summarizes some of the current "bugs"
in JavaScript that you should be aware of and lists a few of the
new features hinted at by Netscape in future releases of Netscape
Navigator. By the time you have this book in your hands many of
these bugs may indeed be fixed (as well as new ones discovered),
but you will be able to gain some insight into why JavaScript
behaves as it does in your version.
Before addressing the new features targeted for release in Netscape
Navigator 2.1 and 3.0, lets look at some of the items that represent
current bugs in Netscape's JavaScript. These are presented here
to help you avoid hours of head scratching and recoding, only
to find out that it's not really your fault. To find out if these
have been fixed in your version of Netscape, go to the Release
Notes section in Navigator. In Windows, select Release Notes from
the Help menu; in Macintosh, select Release Notes from the Balloon
Help menu. The following items are a few of the current bugs in
Netscape's 2.01 version of JavaScript, and ways to avoid them:
- onLoad event handler loads prematurely-The onLoad
event handler may get called before it is supposed to when
you use pages without frames. To work around this, use window.setTimeout()
to test for the existence of form elements in your page before
running the script you intended for the onLoad event.
- Unterminated String Literal error message-This occurs
when you try to assign a very long string to a text value (see
listing D.1).
Listing D.1 Long Strings Literals in JavaScript
var thisString="Wow this is a long string of code which
will not work in current versions of Netscape! Especially Windows
3.1. Wow this is a long string of code which will not work in
current versions of Netscape! Especially Windows 3.1. Wow this
is a long string of code which will not work in current versions
of Netscape! Especially Windows 3.1. Wow this is a long string
of code which will not work in current versions of Netscape! Especially
Windows 3.1."
- To fix this, break the string into smaller pieces and concatenate
them together using the plus operator (+).
- Eval() crashes Navigator in Windows 3.11-This is
a known bug and the next version should take care of this. In
the mean time, avoid using eval() or check the appVersion
(for example, navigator.appVersion) of the client machine
and direct them around this code if it is being run on Windows
3.11.
- window.open() only opens an empty window-In Macintosh
and X versions of Navigator you have to send the window.open()
message twice for the information to be passed to the window.
If you only send it once, you get a blank open window. This bug
should be fixed in 2.1.
- Opening a new window in some X platforms ignores Boolean options-When
you open a window you can specify items such as toolbar=yes, and
so on. Some versions of Navigator for X ignore this. You should
always specify the options for the window.open() method
to avoid this problem. Look for a fix in 2.1.
- Height and width in IMAGE tags-You should always include HEIGHT
and WIDTH attributes on all your images to avoid this bug where
event handlers might be ignored on form elements below the images.
Another less elegant work- around is to add an empty <SCRIPT>...</SCRIPT>
tag to the bottom of that page.
- lastIndexOf searching-Normally, the lastIndexOf method
should start searching right to left based on the position you
specified in the fromIndex value. As of now, it starts one character
to the right of that position.
- method property of a form object-Right now this property is
read-only (in 2.01) but you should be able to reset the value
of this property in your scripts. Look for a fix in 2.1.
- document.close()-If you call document.close() while
a document you opened is still loading, it causes Navigator to
crash. Check to make sure the document has completely loaded before
you call document.close().
- name property of object and order of creation-When you give
the same name to multiple objects in a form, JavaScript is supposed
to create an array with each of those objects in order of creation.
If you don't specify an event handler with this object, the indexing
will be in reverse of the creation order. This bug shows up most
often when you use radio buttons in a form. You should add an
event handler to each element (even if the event handler does
nothing) in order for them to be indexed correctly.
- window.status property-If you check the window.status
property, it is always the value of window.defaultStatus.
What it should actually be is the current value of this window's
status bar instead of a constant value. This will be fixed in
an upcoming version to reflect the current status instead.
- window.open() and spaces in names-Calling a window.open
with a name containing spaces doesn't work, but doesn't call
an error message. For example,
window.open("", "Hi There")
simply does not work, nor does it give you an error message.
Always check that you don't use spaces. The fix in 2.1 will give
you an error message.
- SCRIPT tags inside table cells-SCRIPT tags
inside table cells that write some HTML don't work in 2.0-the
HTML is written twice, and the first output is misinterpreted
as if it were JavaScript within the SCRIPT tag, during the second
pass. To work around this, invert things so your SCRIPT tag writes
the table cell markup and the generated HTML (document.lastModified),
as follows:
<TABLE WIDTH=100%><TR>
<SCRIPT LANGUAGE="JavaScript">
document.write("<TD>", document.lastModified,
"</TD>")
</SCRIPT>
</TR></TABLE>
- Math.random()-Currently, this only works on some
X platforms. It is to be fixed in 2.1.
- onMouseOver in Navigator Gold in Windows-Currently this feature
is not working. Look for a fix in the next release of Navigator
Gold.
- Inter-frame and inter-window string and object references-When
you reference a string or an object across frames or windows,
the value can get corrupted. You should instead assign the "remote"
value (the one in the other frame or window) to a new "local"
variable. Also, in the instance of strings, you should pre-append
a "" to the new value to make sure JavaScript
reads the value as a string. For example:
var mystr = "" + parent.otherFrame.stringProperty
You should also avoid passing objects between frames and
windows until Netscape version 3.0, which should correct this
corruption problem.
JavaScript has certain limitations built in that most likely will
not change over time. These limitations are tied closely with
the issues of security. Although JavaScript will execute small
"programs" on your machine, you do not want it to send
or receive information that you do not explicitly request.
JavaScript will most likely never be able to directly write to
a file (although recently a script was developed that allows JavaScript
to prompt you to save some data in a file of your choice-much
like when you download an unknown file type). It hopefully will
not be able to access your personal history files (as in sending
them to others). It will not access your e-mail address (again,
as in sending it to another site).
Also, it will probably, in the future, check a site against some
list you develop (or via some RSA security key) and mark a site
as "trusted" or "not trusted" and treat that
script accordingly. Scripts from trusted sites will probably have
greater freedom to manipulate information for you, as well as
perform tasks that untrusted sites would be banned from. There
is also a new concept called information tainting that
will allow scripts to access more sensitive information from your
browser.
Brendan Eich, the engineer at Netscape in charge of JavaScript,
has been working to improve JavaScript with each version of Netscape
that is released. Because of time constraints, many features originally
targeted for the first release have been delayed. The following
section represents some of the features that will be included
in future releases of JavaScript.
Netscape Navigator 2.1 is the next release of the browser to include
new features and bug fixes. This release is expected some time
in the summer of '96 (as of this writing). This release represents
mainly a set of minor changes and improvements over 2.01.
If you read the bug listings earlier in this appendix, you know
much about what will be fixed in 2.1. There are a number of items,
though, that are not considered bugs, which are also intended
to be added to the next version of JavaScript (via the next version
of Navigator-since there is no distinction in terms of versioning).
The following lists some of these features:
- onMouseOver for imagemaps-Currently you cannot use
the onMouseOver event handler to control different actions using
a client-side imagemap. If you place onMouseOver
events in each tag that specifies an area, the Navigator
ignores the tag. In 2.1, you should be able to trigger events
using a client-side imagemap. For example, listing D.2
shows the original map.
Listing D.2 Client-Side Imagemap-Before JavaScript
<MAP NAME=bottom>
<AREA SHAPE=rect COORDS="0,0, 46,31" HREF=/search/index.html>
<AREA SHAPE=rect COORDS="47,0, 106,31" HREF=/ads/index.html>
<AREA SHAPE=rect COORDS="107,0, 163,31" HREF=/misc/contact_info.html>
<AREA SHAPE=rect COORDS= "164,0, 223,31"
HREF="http://merchant.netscape.com/netstore/index.html">
<AREA SHAPE=rect COORDS= "224,0, 285,31" HREF=/toc.html>
<AREA SHAPE=rect COORDS= "286,0, 354,31" HREF=/comprod/mirror/index.html>
<AREA SHAPE=rect COORDS= "355,0, 418,31" HREF=/escapes/galleria.html>
<AREA SHAPE=rect COORDS= "419,0, 468,31" HREF=/feedback/index.html>
<AREA SHAPE=default HREF=/index.html>
</MAP>
- Using onMouseOver you can add to an area an event to be triggered
when a user passes his mouse over that area specified, as follows:
<AREA SHAPE=rect COORDS="0,0, 46,31" HREF=/search/index.html
onMouseOver="alert('hi!')">
- Currently, if you want events to be triggered by an imagemap,
you must use the javascript: URL tag in an HREF link. For example,
the preceding line would read as follows:
<AREA SHAPE=rect COORDS="0,0, 46,31" HREF="javascript:alert('hi!')">
The limitation to this is that the user must click that area
in order for the script to be executed.
- Security fixes-There are many security issues that will be
addressed in the next version of Navigator. In 2.1, JavaScript
will have much of the same limitations that Java currently has
in terms of writing to the user's local machine, or getting personal
information from the client back to the server-such as mail addresses
or listings of files.
- Overall stability-You may notice that JavaScript crashes your
machine, or brings up an Out of memory error on a page using a
clock or some other constantly running script. This is primarily
due to the machine not freeing up memory as it becomes available
(especially with recursive calls to setTimeout()), and will be
fixed in 2.1.
The 3.0 release of Netscape Navigator will include a host of new
features in addition to improvements of JavaScript. For instance,
it will use Collabra Share, video and audio streaming, Live3D
(VRML), and a second generation Java engine. The following is
a short listing of the expected changes to JavaScript that have
been announced through various channels via the Internet:
- Regular expressions-Many scripting languages use a feature
called regular expressions. Regular expressions are a set of characters
that follow certain rules to match characters in a string. What
this means to the JavaScript programmer is that you will be able
to search for text based on rules like "Find all five character
strings that begin with C and end with ch."
- Languages like Perl take great advantage of this ability to
parse through submissions of forms via the Web. There will probably
be a whole new set of statements for this capability, such as
a find() method or a regex() method.
- Printing-When a user retrieves a Web page containing JavaScript
that generates HTML on-the-fly in some way (such as saying "Good
Evening" at night using the Date object), he currently cannot
print the page in the same way that it is displayed on the browser.
Instead, the page is printed with blank areas where the generated
HTML should have been, or the source code appears (if the page
programmer did not use the comment tags to hide the code). This
is because of the way the Navigator stores the information that
it uses to create the page. Essentially, when a page is printed,
it is reread by the browser and converted to the correct code
to be sent to the printer. Unfortunately, this interpreter does
not recognize JavaScript code. It's as if your browser is of two
minds-the new browser, which understands the JavaScript elements,
and the older browser, which ignores the commands. In this release,
you should be able to print source pages as "generated source"
or just "source."
- SRC tag-When JavaScript was originally released,
it listed the SCRIPT tag as having an attribute called
SRC. For example,
<SCRIPT SRC="http://www.mysite.com/foo/scripts/hello.js">
</SCRIPT>
- In the 3.0 release, you will be able to hide the source code
of your scripts using this SRC tag. It operates much like it would
for the IMG tag. Your JavaScript code is written in a file that
has a .js extension, which you then can reference from anywhere
on your pages without having to relist the code over and over
again across pages. What is interesting about this new attribute
is that it not only will allow you to modularize your JavaScript
code, but all of your HTML code. For instance, take a look at
a simple example in listing D.3.
Listing D.3 Simple HTML Example
<HTML>
<HEAD>
<TITLE>Welcome to my Site!</TITLE>
</HEAD>
<BODY>
<H1>Today's Date is July 14, 1996!</H1>
Welcome.....blah blah
<address>my@address.com</address>
</BODY>
</HTML>
- Using the new SRC attribute in the SCRIPT tag, you can pull
out all of the parts of a page that are reused across your Web
site and just point to them from inside a <SCRIPT SCR="">.
Listing D.4 is the small page converted to a series of scripts.
Listing D.4 Alternative Code Using JavaScript SRC
Attribute
<HTML>
<HEAD>
<SCRIPT SRC="mytitle.js"><SCRIPT>
</HEAD>
<BODY>
<SCRIPT SRC="todaysdate.js"></SCRIPT>
<SCRIPT SRC="myintromessage.js"></SCRIPT>
<SCRIPT SRC="myaddress.js"></SCRIPT>
</BODY>
</HTML>
- This might not seem to save much space at first, but imagine
that you have 200 Web pages, and all of them have your address
at the bottom. Today you get a new e-mail address. You now have
to change your address on 200 pages. Perhaps you know enough UNIX
to globally change your pages, or perhaps you have a script that
might do that as well, but if you don't, you will be editing your
pages for a long time.
- With JavaScript, all you will have to do is change the myaddress.js
file and all of the pages will reflect this new change. In addition,
you can edit your myaddress.js file to point itself to myname.js,
which appends your name to the end of your address. What this
really means is that you will be able to dramatically modularize
your pages.
As with the SRC tag, the JavaScript documentation originally talked
about using JavaScript to read and write properties of plug-ins
and Java applets from within the JavaScript script. This specification
has yet to be completely hashed out, but you will soon be able
to see the properties of applets and plug-ins. There will be two
new Navigator properties: navigator.plugins (an array of plug-ins
that specify all of the currently registered plug-ins) and navigator.mimeTypes
(which specify information about all of the MIME types supported
by that Navigator). Later there will also be document.plugins,
which reflect the information listed in all of the EMBED tags
of a given page.
It's expected that you will also have something like navigator.applets
that will correspond to the APPLET tag listings.
To get or change attributes of these new properties you will use
navigator.plugins[0].propertys[0], or something similar.
JavaScript has a bright future if it can keep up with the rapid
pace of change that has been the norm for the past few years in
the software and Internet development world. JavaScript is relatively
robust and useful, and adds a new dimension of interactivity to
the Web. There has been a general trend in the computer industry
to pass more work off to the client machine, which now has the
processing power to handle it. JavaScript continues this trend
by allowing you to avoid using CGIs for many tasks. And with the
development of server-side JavaScript, Web sites will probably
become more like full blown applications-instead of their current
relatively static nature.