'activex outlook bring to front

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 = '[email protected]';
        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.



Solution 1:[1]

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.

Solution 2:[2]

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 = '[email protected]';
mailItem.display();
mailItem.Attachments.add(emailAttach);
app.ActiveExplorer.Activate();

var sInspector = new ActiveXObject('Redemption.SafeInspector');
var oInspector = mailItem.GetInspector;
sInspector.Item = oInspector;
sInspector.Activate();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev
Solution 2