1. Computing & Technology

Automatic document.write Replacement

Getting Rid of document.write Automatically

Join the Discussion

Questions? Comments?

Related Reference

Getting Rid of document.write

Not everyone knows how easy it is to replace all the document.write statements in antiquated JavaScripts. Well for those people the form on this page is just what you are looking for to perform that modification to the scripts you have that unfortunately use the antiquated document.write or document.writeln statement to output content into the web page.

What we are going to do is to create a tag that can be pasted into the code at the script location. The script itself can then immediately follow or be placed anywhere lower in the page. This generator will even generate the correct script tag for you since scripts that use document.write likely have obsolete references in the script tag as well.

Simply type in the name of your script file in the first field in the below form and paste a copy of the entire script into the second field (the first textarea). When you press the convert button your replacement HTML and Script will appear below. The HTML can either be pasted exactly as shown in place of the original script tag or you can just place the div tag there and move the script tag itself to the bottom of the page. The script code itself simply needs to be pasted into the JavaScript file in place of the code you originally copied from there into the form.

document.write Eliminator







Note that this script uses the filename without the .js suffix as the id that it needs and also uses that same value with 'jsdw' added to it as a temporary field name in the updated script. In the unlikely event that these would clash with the code you should specify a different value for the filename and then simply update the src attribute in the generated script tag back to your required filename. It is unliklely you will need to do this though.

Note also that this converter will not work if the code is obfuscated so that the document.write references do not appear in the code as document.write.

©2012 About.com. All rights reserved.

A part of The New York Times Company.