在Windows 7中使用JavaScript/JScript将拼写检查窗口置于前台 [英] Bring spell check window to foreground with JavaScript/JScript in Windows 7

查看:101
本文介绍了在Windows 7中使用JavaScript/JScript将拼写检查窗口置于前台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些JScript代码(从一些旧的VBScript转换而来)是这样的:

I have some JScript code (converted from some old VBScript) that starts like this:

var Word = new ActiveXObject("Word.Basic");

Word.FileNew(); // opens new Word document
Word.Insert(IncorrectText);
Word.ToolsSpelling(); // opens spell check behind IE

这个想法是利用MS Word拼写检查供浏览器使用,并且在XP中效果很好,但是拼写检查框在Windows 7/IE 8中在后台打开(

The idea is to utilize the MS Word spell check for browser use, and it works well in XP, but the spell check box opens in the background in Windows 7 / IE 8 (this question tells me that the problem started in Vista and is probably an OS issue, not a browser or Office issue).

所以我的问题是,如何将这个窗口置于前台?一个重要的注意事项是,最后一行Word.ToolsSpelling();锁定了我的脚本,因此我需要做的一切都在此之前.

So my question is, how can I bring this window to the foreground? One important note is that the last line, Word.ToolsSpelling();, locks up my script, so anything I do will need to be before that.

我尝试过

var wshShell = new ActiveXObject("WScript.Shell");
wshShell.AppActivate("Document1 - Microsoft Word"); // or some other text

在ToolsSpelling调用之前,但这不会执行任何操作(可能是因为此时Word文档实际上并未显示出来?).当然,这仅在尚未打开"Document1"的情况下才有效,因此从一开始就令人怀疑.

before the ToolsSpelling call, but this does not do anything (maybe because the Word document is not actually revealed at this point?). Of course, this will only work if no "Document1" is already opened, so this is a questionable thought to begin with.

每个

Per this answer, I tried using window.blur(); in order to blur IE, but this will only work if the IE window is the only one opened. Maybe there's some way I can loop through all opened windows and apply this?

SetForegroundWindow 看起来很有希望,但是我不知道如何在JSript中使用它.

SetForegroundWindow looked promising, but I don't know how to use it in JSript.

有什么想法吗?

注意:该网站的浏览器权限将完全打开.

Note: Browser permissions will be completely open for this site.

更新:事实证明,如果您使用Word.Application,则拼写检查应显示在前面.只有Word.Basic方法有此问题(我不希望知道为什么这永恒的一面):

Update: Turns out if you use Word.Application, the spell check comes up in front as it should. Only the Word.Basic method has this problem (I don't expect to know why this side of eternity):

var wordApp = new ActiveXObject("Word.Application");
wordApp.Documents.Add();
wordDoc = wordApp.ActiveDocument;
... // safety checks before insertion
wordSelection.TypeText(IncorrectText);
wordDoc.CheckSpelling();
wordApp.Visible = false; // CheckSpelling makes the document visible

推荐答案

您也许可以微调窗口状态.最小化后最大化窗口时,Windows会将其堆叠在最前面(zIndex到顶部).

You might be able to jigger the window state. When the window is maximized after having been minimized, Windows will stack that in front (zIndex to top).

类似的东西:

 var WIN_MAX = 2;
 var WIN_MIN = 1;

 var Word = new ActiveXObject("Word.Application");
 Word.Visible = true;
 // minimize the app
 Word.WindowState = WIN_MIN ;
 // in 500ms, maximize
 setTimeout(function () {
     Word.WindowState = WIN_MAX;
 }, 500);

setTimeout调用试图解决计时问题;当立即连续发生程序化的最小化/最大化操作时,Windows有时会感到困惑".您可能需要稍微延长一下延迟时间,反复测试一下,看看会得到什么样的结果.

The setTimeout call seeks to work around a timing issue; Windows will sometimes "get confused" when a programmatic minimize/maximize happens in immediate succession. You might have to extend that delay a little, test it repeatedly and see what kind of results you get.

这篇关于在Windows 7中使用JavaScript/JScript将拼写检查窗口置于前台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆