Results 1 to 3 of 3
Thread: Open and close web browser
- 11-03-2009, 06:17 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 29
- Rep Power
- 0
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.
Ali.
- 11-03-2009, 12:04 PM #2
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.setRequestMethod("GET"); connection.setUseCaches (false); connection.setDoInput(true); connection.setDoOutput(true); //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) { response.append(line); response.append('\r'); } rd.close(); } statusCode = connection.getResponseCode(); } catch (Exception e) { statusCode = 500; e.printStackTrace(); } finally { if(connection != null) { connection.disconnect(); } } return statusCode; }
- 11-03-2009, 12:28 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 29
- Rep Power
- 0
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);
//Thread.sleep(5000);
System.out.println("Hello 5" + " " + Url);
p.destroy();
If i dont use
sleep
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.
Ali
Similar Threads
-
Different Files Open in File -> Open Workspace
By mgm2010 in forum JCreatorReplies: 0Last Post: 04-11-2009, 02:14 PM -
[SOLVED] How to close the current form when i open a new form?
By tpyq in forum NetBeansReplies: 6Last Post: 11-28-2008, 06:55 AM -
Re-open browser
By Tokajac in forum Java ServletReplies: 2Last Post: 10-13-2008, 01:31 PM -
How to close an open JFrame window from a jsp page?
By kasisaiganesh in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-27-2008, 06:29 PM -
What could be causing the browser to close?
By Marcus in forum Java AppletsReplies: 2Last Post: 07-04-2007, 07:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks