Forum Discussion

techgirlbb's avatar
techgirlbb
Contributor
7 years ago
Solved

Closing browser windows if Open

Hi I am trying to write a function in JavaScript to close the browser if open else display message:

function ClosingApplications2()

{

var p ;

p=Sys.Browser("iexplore");

if (p.Exists){

p.Close();

}

else

Log.Message("No active window");

}

 

it is working fine if the browser is open. If browser is not then failing with Object not found  and then moving to else condition.. guide me where I am missing..

 

 

  • I actually go a little lower level to go beyond just browser to actually checking the process.  This is code I cobbled together from several sources.  This works for IE.  I'm assuming it could be adapted to work for any browser process.

                var counter = 0;
                var browser = Sys.WaitProcess('iexplore', 1000);
                while((browser.Exists)){
                    browser.Terminate();
                    browser = Sys.WaitProcess('iexplore', 1000);
                }

2 Replies