LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Javascript spell check (https://www.linuxquestions.org/questions/programming-9/javascript-spell-check-99063/)

slightcrazed 10-01-2003 12:52 PM

Javascript spell check
 
OK,
I have been 'volunteered' for a little project here at work. We have an HTML application that is our main customer database, but it has no in-built spell check feature. Management would like to spell check documentation that is entered into a customer's file. I have no direct access to the HTML application, so the only way I can interact with it is though the .hta file that loads the application. Here is my problem:

I have found a nifty little Javascript that will copy selected text from a web page, paste it into Word, run Word's built in spell check, and then paste the changes back into the original document. Code:

Code:

<HTML>
<HEAD>
<TITLE>NaviLink</TITLE>
<HTA:APPLICATION ID="htaNavLink"
  APPLICATIONNAME="NavLink"
  BORDER="thick"
  CAPTION="yes"
  SHOWINTASKBAR="yes"
  SINGLEINSTANCE="no"
  SYSMENU="yes"
  WINDOWSTATE="normal"
  NAVIGABLE="yes"
  SCROLL="yes"
  SELECTION="no"
  MAXIMIZEBUTTON="yes"
  MINIMIZEBUTTON="yes"
  INNERBORDER="no"
  CONTEXTMENU="yes">
<script language="JScript">

function spellcheck()
{oShell= new
ActiveXObject("WScript.Shell");
oShell.SendKeys( "^c" ); // copy
oWord= new ActiveXObject("Word.Application");
oWord.Visible= true;
oWord.Documents.Add();
oWord.Selection.Paste();
oWord.ActiveDocument.CheckSpelling();
oWord.Selection.WholeStory();
oWord.Selection.Copy();
oWord.ActiveDocument.Close(0);
oWord.Quit();
var nRet= oShell.Popup(
"Apply changes?\nClick OK to replace all selected text.",
0,
"Spell Check Complete",
33 );
if ( nRet == 1 ) {
oShell.SendKeys( "^v" ); // paste
}}
</script>
</HEAD>
<BODY STYLE=Margin:0px ONLOAD=LoadApp()>
<table border="0" width="100%"><tr>
<td><input type="button" id="BB" class="clsButton" value="SpellCheck"
onClick="spellcheck()"></td>
</table>
<IFRAME ID="fraApp" APPLICATION="Yes" STYLE="Width:100%;Height:100%;"></IFRAME>
<script language=vbScript>
        Sub LoadApp()
                window.moveTo 0, 0
                window.resizeTo 1025, 735
                document.all.fraApp.src = "http://comapny/program.htm"
        End Sub
</script>
</BODY>
</HTML>

As you can see, the application is being loaded in an iframe. For some strange reason that is well beyond my very limited capabilities, the application in the iframe doesn't respond to the sendkeys command. So no text is being copied, and the spell check fails.

Any ideas on what I might be missing? I know that within the application pressing ctrl+c and ctrl+v work well enough for copy paste, but I don't know how to code this into the script.

I probably did a real bad job of explaining the problem, so let me know if I can clarify.

slight

nephilim 10-02-2003 07:39 AM

This is just a guess, but shouldn't you select something first, like

oShell.SendKeys( "^a" ); // select all

slightcrazed 10-02-2003 10:05 AM

I have tried select all via the sendkeys command, and also just by highlighting with the mouse, and neither works. It's as if the document in the <iframe></iframe> is oblivious to the command, like it's seperate from the rest of the document.

thanks for the suggestion though.

slight

lackluster 10-02-2003 04:08 PM

..... I have a spell-checker written in JavaScript I did for a project .... e-mail me if you want it. It does require
1.) JavaScript (duh!)
2.) server-side language (asp, php, etc.)
3.) database or flat files

if you have asp/perlscript and sql server you won't even need to change it.


All times are GMT -5. The time now is 01:56 PM.