Categories:
Partners
Web Hosting
We've partnered with HostGator for reliable, affordable hosting starting at $3.95/mon. Use coupon code "javascriptkit25" for 25% off any package.

Using the JavaScript library syntax to overcome a document.write() bug

Deviating a bit, let's talk about a little lady bug found in the document.write() method. The document.write() method, when used inside a table to write out text, can cause problems when viewed under NS 3 (only NS 3-). Specifically, the output does not show! For example, if I were to include the below script at this point in the page:

<script>
document.write("hi there")
</script>

Viewers of NS 3 would see nothing, nada. The reason is because the code is inside a table, and the document.write() method has trouble displaying the text when it's inside a holding cell for NS 3- users. The solution? While it's definitely not pretty, one way to work it so the text shows for NS 3 users is to embed the code inside a JavaScript library. For some reason known only to the creators of the NS browser, it works. So, assuming you've embedded the above document.write() code inside a JavaScript library called "writetext.js", you would call it like any library to display the text:

<script src="writetext.js">
</script>
Copyright 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.