Results 1 to 3 of 3
  1. #1
    ali_sakar is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default Open and close web browser

    Hi all,

    My requirement is to fire a particular URL through my java program. I am able to achieve the same but the problem is it opens up my IE but doesnt closes it. I call this java program in a loop.

    How do i open a web browser(platform independent), fire the URL and then close the web browser.

    Thanking in advance.


  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    i don't know of any way to have the external to the browser Java program close the browser. the browser would be opened from your program by an operating system dependent manner too right.

    does the web browser display anything ? it might be possible to have the page that is displayed contain some javascript to do a kind of 'window.close()' thing. that might still only prompt the user to ask if they are sure they want the script to close the window.

    if your program just needs to invoke a url to have the server do something because that url got invoked, would it be possible to do this directly from your code instead of opening a browser in the first place ?

    for example,
    Java Code:
    * performs a HTTP GET to a url
    * @param response if not null, the HTTP GET response is read into this.
    * @return the http response code.
    int invokeUrl(URL url, StringBuffer response) {
        int statusCode = 0;
        HttpURLConnection connection = null;  
        try {
          //Create connection
          connection = (HttpURLConnection)url.openConnection();
          connection.setUseCaches (false);
          //Get Response  
          if (response != null) {
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuffer response = new StringBuffer(); 
            while((line = rd.readLine()) != null) {
          statusCode = connection.getResponseCode();
        } catch (Exception e) {
          statusCode = 500;
        } finally {
          if(connection != null) {
        return statusCode;

  3. #3
    ali_sakar is offline Member
    Join Date
    Feb 2009
    Rep Power


    Thanx for the reply.

    I cannot have a javascript on that page coz its a link provided by a third party. I just have to call this link after changing a couple of values. I have used

    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe" +" " + Url);
    System.out.println("Hello 5" + " " + Url);

    If i dont use


    statement in between then i dont see anything happening on my screen. But if i use sleep then multiple instances of IE opens up, fires the URL passed to it but doesnt closes it.


Similar Threads

  1. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 02:14 PM
  2. Replies: 6
    Last Post: 11-28-2008, 06:55 AM
  3. Re-open browser
    By Tokajac in forum Java Servlet
    Replies: 2
    Last Post: 10-13-2008, 01:31 PM
  4. How to close an open JFrame window from a jsp page?
    By kasisaiganesh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-27-2008, 06:29 PM
  5. What could be causing the browser to close?
    By Marcus in forum Java Applets
    Replies: 2
    Last Post: 07-04-2007, 07:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts