从javascript打开Word并显示在最前面 [英] Open Word from javascript and bring to front

查看:95
本文介绍了从javascript打开Word并显示在最前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从javascript中打开Word文档:

I'm using the following code to open a Word document from javascript:

    function openWord(file) {
    try {
        var objword = new ActiveXObject("Word.Application");
    } catch (e) {
        alert(e + 'Cannot open Word');
    }

    if (objword != null) {
        objword.Visible = true;
        objword.Documents.Open(file);
    }
}

这很好用,唯一的问题是Word应用程序在打开时不会位于最前面,而是在浏览器后面打开. 有没有一种方法可以强制Word在其他任何窗口的顶部打开?还是将其打开时放在前面?

This works fine the only problem is that the Word application does not come to the front when opened, instead it opens just behind the browser. Is there a way to force Word to open on top of any other window? or to bring it to front when its open?

推荐答案

不是很完美,但这对我有用:

Not exactly perfect but this worked for me:

$(document).ready(function() {
  $("#open").click(function() {
    openWord('https://www.google.com.mx/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjp7ajpqoTLAhUUwGMKHc3UB5AQFggbMAA&url=http%3A%2F%2Fblog.espol.edu.ec%2Fgfflores%2Ffiles%2F2012%2F02%2FC%25C3%25B3digo-de-Hola-Mundo-para-Simulador-BlackBerry.docx&usg=AFQjCNHoFTUJxMonRG1lpr44K9eZjuxEvA&sig2=9bgOMw8yYzWhFXz0q_JbKg');
  });
});

function openWord(file) {
  try {
    var objword = new ActiveXObject("Word.Application");
  } catch (e) {
    alert(e + 'Error Word');
  }

  if (objword != null) {
    objword.Visible = true;
    objword.Documents.Open(file);
    objword.WindowState = 2;
    objword.WindowState = 1;
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="open">Try</button>

它仍然在后台打开Word,但随后强制最小化-最大化并将其置于最前面.

it still opens Word in the background, but then forces a minimize - maximize and brings it to front.

这篇关于从javascript打开Word并显示在最前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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