Spell Checker Interface v1.4 for Aspell

This Spelling Checker Interface is an ASP based web interface (front end) to Aspell/Ispell. This code incorporates ASP VBScript code to interface to Aspell and Javascript/HTML for the human interface. All of this is bundled into one small .asp file.

If you are using Aspell, FCKEditor, Web Wiz Rich Text Editor or a text area box, then you should be able to implement this code in a snap. You can alter this code to fit other programs etc, but you will have little bit of work to do. This is not hard for a web programmer, but may be difficult to a newbie.

What is Aspell?

GNU Aspell is a Free and Open Source spell checker designed to eventually replace Ispell. It can either be used as a library or as an independent spell checker. Its main feature is that it does a much better job of coming up with possible suggestions than just about any other spell checker out there for the English language, including Ispell and Microsoft Word. It also has many other technical enhancements over Ispell such as using shared memory for dictionaries and intelligently handling personal dictionaries when more than one Aspell process is open at once.

For more information, visit the Aspell web site: aspell.net (if you go to the main page, select Windows port)
Version tested with: Aspell 0.50.3  (Ispell 3.1.20) and 0.50.5 pre-release
Download and install the Full Installer (spelling engine) as well as a dictionary (separate downloads).

What is FCKEditor?

This is my preferred free HTML editor. It is an ASP and Javascript client side editor. I am using this as my launch platform for the spell checks. This editor is very functional and is updated often - only negatives are that version 1.4 does not support Mozilla/FireFox - although v2.0 will and it initialise via an ActiveX object. See the below section for my usage tips.
The FCK Editor (which is not named after anything rude) brings to the web many of the powerful functionalities of known desktop editors like Word (to a degree). It's really lightweight and doesn't require any kind of installation in the client computer. As it is Open Source, you are allowed to use it for free wherever you want.

For more information, visit the FredCK web site: http://www.fredck.com/fckeditor/
Version tested with: FCK Editor 1.4 & 1.5 (1.6 should also be ok but may need some rework on the SpellCheck function - I have not tried this yet)
See below for tips to modify this editor to link to the spell checker.

What is Web Wiz Rich Text Editor?

This was my preferred HTML editor. It is an ASP and Javascript client side editor. You can use this as a launch platform for the spell checks. This editor is very functional and is updated often - only negatives are that there is no help files - only a messy forum where the FAQs are stored and it requires their copyright and web links plastered all over it. See the below section for my usage tips.
The Web Wiz Rich Text Editor allows you to have the ability of changing any HTML text area on your web site into a WYSIWYG Editor. With multi browser and cross platform support. With many features and simple to setup you can easily integrate this Rich Text Editor into your site or projects replacing basic form text areas into a WYSIWYG Editor allowing your visitors to see what there form input will look like before submitting a form. You can also allow toggling between WYSIWYG view and HTML view to allow more advanced users to edit the HTML directly.

For more information, visit the Web Wiz web site: www.richtexteditor.org
Version tested with: Web Wiz Rich Text Editor 1.2c
See below for tips to modify this editor to link to the spell checker. Also other tips to improve the editor itself.

How does this interface work?

The source editor posts the document text to this interface. (in a small popup window). If not posted, the script will pull the text from the selected field.
The text is written to a temporary text file.
The Windows Scripting Host or ASPExec is used to execute Aspell in piped HTML mode.
ASP reads the results, interprets them and then configures/populates Javascript to drive the human interface.
Javascript - via the HTML form, shows each misspelling and suggestions for it. The word is also highlighted in white on red in the original window.
When a a word is selected/replaced, that word is replaced in the original window.
When data is pushed back to the original window - the entire text is pushed from an internal buffer. If you edit the document in the middle of a spell check, then those changes will be lost when you replace the next word.

Windows Script Host

Windows Script Host (WScript.exe) is generally installed with windows, but not necessarily. If you find that it is not installed, it can be downloaded from Microsoft: www.microsoft.com/downloads
See the Permissions / Issues section below for more information about getting this thing to run or alternatives.

Query String Parameters

Parameter: Editor
Options: F = FCKEditor, W = Web Wiz, T = Text Area box
Notes: Defaults to W if not specified.

Parameter: HTMLDoc
Options: Y = Yes, N = No, <blank> = auto
Notes: Only specify if you wish to override the auto selection (based on the Editor parameter).

Parameter: FormField
Options: FormName.FieldName
Notes: This is the form and field name of the text you wish to check. This is only used when you do not post the text to the spellchecker.asp page (aka Pull mode).

Example: SpellChecker.asp?Editor=T&HTMLDoc=&FormField=editForm.Text

Changes to the Spell Check Interface code

If you have any differences to the setup which I am using, then you will need to alter a couple of things in the spellchecker.asp file. Here is a list of the most likely changes:

Permissions / Issues

The art of executing a exe file on a web server is rather tricky. You can use the Windows Script Host, MS SQL Server, Windows Management Interface, or a 3rd party COM object. When using the Windows Script Host, if you get permission denied, access denied or a file not found error try these fixes - testing between each:

1. Lower the IIS Application Protection (under IIS Porperties, Home Directory) set to "Low (IIS Process)". This will generally always work.
2. Try Option 2 (commented out in the code). This uses ASPExec (http://www.serverobjects.com/products.htm) which works nicely, but you must copy, install and register a DLL onto your server.
3. The Windows Script Host needs to execute a file - this requires more permissions than what IIS generally has by default. There is several different thing you can try if you get permission denied or simply nothing. IIS runs with it's own Windows login account which is named IUSR_xxxxx, where the x's are the computer name, generally. This method is not exactly best practice for the Internet service - in fact it should never be done on production web servers. To do this, create a new account in Windows and then assign it to the Administrator group. Then in IIS, tell it to use this account (in Web Site Properties, Directory Security, Anonymous Access - Edit, Anonymous Access - User Name). Scared yet? ok, skip to the next suggestion then.
4. If you have a local MS SQL Server database, you can create a new user for this and give it permissions to run the Extended Procedure xp_cmdshell. I have dropped some code in the ExecOptions.asp file to show how this works.
5. I have left some of my test code for WMI execution commented out. I can not get this working. Maybe you will have better success. (see ExecOptions.asp)

If you a better way to execute a program, please let me know. I've searched all over the web and found nothing works seamlessly in ASP due to the piping required for Aspell.

Not supported yet / Bugs

Suggested code for your Text only Editor

Here is the basic code for a text only editor. See SpellCheckTextDemo.asp for a full demo of this code. This code pulls the text into the checker (using PULL method) as you are most likely posting the form elsewhere. You can POST the text too. See the SpellCheckPost function in SpellCheckTextDemo.asp for an example of posting.

<script language="javascript">
function SpellCheck () {
  //We won't post the contents this time. I will use the "pull" method.
  sc = window.open('spellchecker.asp?Editor=T&FormField=spellchecktext.Text','SpellCheck',
<form name="spellchecktext" action="spellchecker.asp?Editor=T&FormField=spellchecktext.Text" method="post">
  <textarea name="Text" cols="80" rows="8">This is a test</textarea>
  <a href="javascript:SpellCheck();">Spell Check</a>

Suggested Changes to FCK (HTML) Editor

Here are the changes to the FCK Editor to integrate it to the spell checker. The line number below refers to version 1.4 & 1.5. Later versions may be different. This code also assumes you have only 1 form on the page.


Line 338 - replace SpellCheck() function:

function SpellCheck() {
    SCWin = window.open('spellchecker.asp?Editor=F','SpellCheck', 'alwaysRaised=0,resizable,scrollbars=0,location=0, height=240,width=180,top=100,left=100');

Suggested Changes to Web Wiz Rich Text (HTML) Editor

Here are some suggested changes to the Web Wiz HTML Editor to make it truly useful - and to integrate it to the spell checker. I can not redistribute the editor in a modified form so I'll explain the changes. I have also copied the changed lines to a text file included with this archive called WebWiz.txt.
The line numbers below refer to version 1.2c. Later versions may be different.


Strip all asp/js to leave bare html and body tags. Nothing in this page is required.


Line 55 - alter table width: width="100%"
Line 104 - alter iframe height= " & cint(request.querystring("Height"))-90 & "
Line 127 - remove input buttons (in response.write)
Line 145 - add javascript code including function insertText():

<script language="javascript">
document.body.onload = insertText;
function insertText() {
    document.getElementById('message').contentWindow.document.body.innerHTML = parent.document.<%=request.querystring("HTMLTextField")%><%=request.querystring("HTMLTextField")%>.value;
} </script>


Line 394 - replace checkspell() function:

function checkspell(){
    document.frmAddMessage.message.value = document.getElementById('message').contentWindow.document.body.innerHTML;
    document.frmAddMessage.action = "spellchecker.asp?Editor=W";
    document.frmAddMessage.target = "SpellChecker";

Embed the editor into your page:
<iframeid="HTMLEditor"src="/HTMLEditor/default.asp?HTMLTextField=FORMNAME.FIELDNAME&Height=400" width="720" height="410" border="0" FRAMEBORDER="0" FRAMESPACING="0" NORESIZE></iframe>
Change the height and width, HTMLEditor directory, FormName and FieldName to match your install.

To read and write to the editor from your parent page (the one with the above iframe in it) use this property in Javascript: HTMLEditor.document.getElementById('message').contentWindow.document.body.innerHTML;

See SpellCheckTextDemo.asp for a text only demo of the code.

If you improve this code, please send me a copy! Thanks!

Hunter Beanland
hunter @ beanland.net.au


Version History
1.4 Made Editor and Field selection a Query String parameter for easy selection. Removed dual pipe exec method. Added ASPExec option. Tidied up HTML.
1.32 Added body onload for doc retrieve screen. Turned on response buffering for those people stuck in the last century (NT4). Thanks to Steve Brereton.

1.31 Fixed FCKEditor readText blanking issue
1.3 Made it simpler to integrate to other editors. Added workaround for ignoring STYLE and SCRIPT tags
1.2 Fixed JS errors with extended chars (>127 in the ASCII table)
1.1 Fixed blank line reading (hilite falling behind bad word). Added support for Aspell 0.50.5 prelease and FCK Editor
1.0 First version.