0

How to bring the outlook application in front which is opened from JavaScript using ActiveX.The following is the code in which I need to bring outlook window on the top (i.e. bring to front), because it is opening behind the I.E. browser.

// Open outlook e-mail client application with the corresponding subject and the attachment link
function openOutlook(emailSubject, emailAttach) {
    try {
        var app = new ActiveXObject('Outlook.Application');
        var objNS = app.GetNameSpace('MAPI');
        var mailItem = app.CreateItem(0);
        mailItem.Subject = (emailSubject);
        mailItem.to = 'test@test.com';
        mailItem.display();
        mailItem.Attachments.add(emailAttach);
    }
    catch (ex) {
        alert('Outlook configuration error : ' + ex.message);
    }
}

So far, I've tried changing mailItem.display(); to mailItem.display(false); and mailItem.display(true); and open-word-from-javascript-and-bring-to-front but it didn't help and there seems to be a glitch here i.e. when I change the code this way and run the app then outlook window comes on the top, but if I open it in another system or open after restarting the system then it doesn't work, I think maybe windows OS is making it come on the top somehow.

Community
  • 1
  • 1
Abdul Mateen Mohammed
  • 1,864
  • 1
  • 12
  • 21

2 Answers2

0

Try to use the Activate method of the Inspector class right after calling the Display() method. It activates an inspector window by bringing it to the foreground and setting keyboard focus.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Is the Activate method you provided in the link from the .NET framework or is it present in JavaScript (by using ActiveX)? – Abdul Mateen Mohammed Apr 24 '15 at 05:53
  • The Activate method belongs to the Outlook object model, it doesn't matter what programming language is used. – Eugene Astafiev Apr 24 '15 at 07:14
  • `var app = new ActiveXObject('Outlook.Application');` In the app variable, I'm able to see Inspectors object but it is empty, could you please provide code snippet in JavaScript, I've to achieve this in the client side. – Abdul Mateen Mohammed Apr 24 '15 at 07:36
0

As of Windows Vista, Windows will not activate a window of an application that is not running in a foreground; it will instead flash the taskbar button.

If you were using C++ or Delphi (or even .Net) you could work around that using AttachThreadInput (see how to make the Outlook Compose window top most?), but you cannot do that from JavaScript.

You can try to use Redemption (I am its author) and its SafeInspector.Activate method, but that means Redemption would need to be installed where you client script runs.

var app = new ActiveXObject('Outlook.Application');
var objNS = app.GetNameSpace('MAPI');
var mailItem = app.CreateItem(0);
mailItem.Subject = "test"
mailItem.to = 'test@test.com';
mailItem.display();
mailItem.Attachments.add(emailAttach);
app.ActiveExplorer.Activate();

var sInspector = new ActiveXObject('Redemption.SafeInspector');
var oInspector = mailItem.GetInspector;
sInspector.Item = oInspector;
sInspector.Activate();
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks Dmitry Streblechenko, but is there any freeware like Redemption and will it be possible by changing settings in Outlook or Windows regedit in the client's machine? – Abdul Mateen Mohammed Apr 24 '15 at 09:51
  • I am not aware of any free software which does this, but you can of course create a small COM object in C++ or Delphi and use it from your JavaScript code. – Dmitry Streblechenko Apr 24 '15 at 13:48
  • Same problem, different scenario : in C# application, opening Outlook and using the GetInspector works for Maximizing but not working to show the window. It still flashes in the taskbar in Windows Server 2008 R2 – Marc Roussel May 09 '17 at 04:57