Javascript to activate another window in a session via AppActivate function

<script type="text/javascript">
    function activatewindow(){
        wshShell = new ActiveXObject("WScript.Shell");
        wshShell.AppActivate("Script");
    }
</script>
<div id="bottom" align="center"><div style="width:80px; padding-top:32px; cursor:pointer;" onclick=activatewindow()></div></div>
</div>

 

Important Notes:

  1. AppActivate, accepts the Windows Title as the argument and operates on those values. 
  2. It supports partial name match by default. That is you can give any of a window title and that respective window will be activated.
  3. If there are multiple windows matching the text of Window title, no operation will be done and no Window change would happen
  4. If there are multiple Windows whose titles match the text you choose, then you need to expand the text or provide the exact window title to the AppActivate

 

PS C:> Select-Window -Title "*editor*"

ProcessName : ScriptEditor
ProcessId   : 6304
IsActive    : False
Handle      : 526424
Title       : PowerGUI Script Editor
Class       : WindowsForms10.Window.8.app.0.3f4995c

 

PS C:>

 

If you have multiple windows of a same processes to be activated one after the other, than you can give list of all windows to AppActivate call in series as shown below:

 

<script type="text/javascript">
function activatewindow(){
wshShell = new ActiveXObject("WScript.Shell");
wshShell.AppActivate("Script");

wshShell.AppActivate("Script Prompt");
}
</script>
<div id="bottom" align="center"><div style="width:80px; padding-top:32px; cursor:pointer;" onclick=activatewindow()></div></div>
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *