注册InternetExplorer活动 [英] Register to InternetExplorer events

查看:81
本文介绍了注册InternetExplorer活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我们需要在Outlook中单击按钮打开InternetExplorer实例。另外,如果有一个这样的InternetExplorer实例(从Outlook打开)已经打开,用户将无法从Outlook打开
InternetExplorer的新实例。以下是我们为实现此目的所采取的步骤:

We have a requirement in where we need to open a InternetExplorer instance on click of button in Outlook. Also if one such instance of InternetExplorer (opened from Outlook) is already opened, user will not be allowed to open a new instance of InternetExplorer from Outlook. Below are the steps that we did to achieve this:


  1. 在插件启动时将布尔变量(isIElaunched)设置为false。
  2. 单击outlook按钮时,启动InternetExplorer实例并将布尔变量(isIElaunched)设置为true。
  3. 注册刚刚启动的InternetExplorer实例的退出事件。
  4. On退出浏览器,再次将布尔变量设置为false。

问题: 从插件测试时,已注册的浏览器事件正在间歇性地工作。但是当从控制台应用程序使用相同的代码片段时,该事件工作正常。以下是我们使用的
代码段。有人可以告诉我出错的地方。

Issue: The registered browser event is working intermittently when testing from plugin. But when using the same code snippet from a console application, the event is working fine. Below is the code snippet what we have used. Can someone advice where I am going wrong.

此外,当使用InternetExplorer.Navigate函数时,它会立即调用Quit事件。

Additionally, when using InternetExplorer.Navigate function, it is immediately invoking the Quit event.

public void onClickOutlookBtn(Office.IRibbonControl control)
{
    string postParams = "param1=param1Val&param2=param2Val";
    string PostHeaders = "Content-Type: application/x-www-form-urlencoded";
    string url = "a sample web url";
    InternetExplorer ieObject = new InternetExplorer();
    ((DWebBrowserEvents_Event)ieObject).Quit += new DWebBrowserEvents_QuitEventHandler(Quit);
     ieObject.Visible = true;
     isIElaunched = true;
     ieObject.Navigate(url, null, null, post, PostHeaders);
}

public void Quit(ref bool Cancel)
{
    System.Windows.Forms.MessageBox.Show(" IE CLOSED");
    isIELaunched = false;

public void Quit(ref bool Cancel)
{
    System.Windows.Forms.MessageBox.Show("IE CLOSED");
    isIELaunched = false;

}

推荐答案

>>>从插件测试时,注册的浏览器事件会间歇性地工作。但是当从控制台应用程序使用相同的代码片段时,该事件工作正常。以下是我们使用的代码&b;


摘录。有人可以告诉我出错的地方。<<<<
$


根据您的描述,我已经做了一个样本试图重现这个问题,但我发现有一些语法错误,我已修复然后运行此示例,遗憾的是,我无法重现它。



添加名为"RibbonIEXml"的功能区(XML)

>>> The registered browser event is working intermittently when testing from plugin. But when using the same code snippet from a console application, the event is working fine. Below is the code 

snippet what we have used. Can someone advice where I am going wrong.<<<

According to your description, I have made a sample to try to reproduce this issue, but I find there are some syntax errorr, I have fixed then run this sample, unfortunately, I can't reproduce it.

Add Ribbon(XML) named "RibbonIEXml"
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group id="MyGroup"
               label="My Group">
          <button id="btnIE" label="Internet Explorer" onAction="onClickOutlookBtn"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>


回调代码:

Callback code:

bool isIELaunched = false;
public void onClickOutlookBtn(Office.IRibbonControl control)
{
    string postParams = "param1=param1Val&param2=param2Val";
    string postHeaders = "Content-Type: application/x-www-form-urlencoded";
    string url = "https://www.google.com.sg/?gfe_rd=cr&ei=11SEV9r4K-HN8ge55IywCA";
    InternetExplorer ieObject = new InternetExplorer();
    ((DWebBrowserEvents_Event)ieObject).Quit += new DWebBrowserEvents_QuitEventHandler(Quit);
    ieObject.Visible = true;
    isIELaunched = true;
    ieObject.Navigate(url, null, null, postParams, postHeaders);
}
public void Quit(ref bool Cancel)
{
    System.Windows.Forms.MessageBox.Show("IE CLOSED");
    isIELaunched = false;
}





这篇关于注册InternetExplorer活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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