Opening a browser only with body from a java program
Hi all,
I got following requirement, Opening a browser window only with body and title bar. And based on some condition, after some time, i have to close the browser window.
I tried with following code. But it opens the browser with menu bar, address bar and etc.
And I don't know how to close this browser window. Please help me in resolving this problem.
Here is my code:
import javax.swing.JOptionPane;
import java.util.Arrays;
public class BareBonesBrowserLaunch {
//"google-chrome", "firefox", "opera", "epiphany", "konqueror", "conkeror", "midori", "kazehakase", "mozilla"
static final String[] browsers = {"Microsoft Internet Explorer"};
static final String errMsg = "Error attempting to launch web browser";
public static void openURL(String url) {
try { //attempt to use Desktop library from JDK 1.6+
Class<?> d = Class.forName("java.awt.Desktop");
d.getDeclaredMethod("browse", new Class[] {java.net.URI.class}).invoke(d.getDeclaredMethod("getDesktop").invoke(null),new Object[] {java.net.URI.create(url)});
//above code mimicks: java.awt.Desktop.getDesktop().browse()
}
catch (Exception ignore) { //library not available or failed
String osName = System.getProperty("os.name");
try {
if (osName.startsWith("Mac OS")) {
Class.forName("com.apple.eio.FileManager").getDeclaredMethod("openURL", new Class[] {String.class}).invoke(null,new Object[] {url});
}
else if (osName.startsWith("Windows"))
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " + url);
else { //assume Unix or Linux
String browser = null;
for (String b : browsers)
if (browser == null && Runtime.getRuntime().exec(new String[]{"which", b}).getInputStream().read() != -1)
Runtime.getRuntime().exec(new String[] {browser = b, url});
if (browser == null)
throw new Exception(Arrays.toString(browsers));
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, errMsg + "\n" + e.toString());
}
}
}
public static void main(){
BareBonesBrowserLaunch.openURL("url");
}
}
Thanks & Regards,
Suresh.
View Answers
January 2, 2012 at 4:21 PM
Ads
Related Tutorials/Questions & Answers:
Opening a browser only with body from a java program
Opening a
browser only with
body from a
java program Hi all,
I got following requirement,
Opening a
browser window
only with
body and title bar. And based on some condition, after some time, i have to close the
browser window
Java - Opening a URL from an Applet
Java -
Opening a URL
from an Applet
 ... used for
opening url
from an applet. This
program is using two functions... window
from an applet. This
program shows that
how a url is opened in same
Advertisements
opening new browser with new JSESSIONID using java
opening new
browser with new JSESSIONID using java I am facing following problem, I am trying to open a new
browser using
java. First i have opened one IE
browser and manually. And i ran my LaunchURL.java file, it is
opening new
Opening files with .jnlp extension on browser!?!?!
Opening files with .jnlp extension on
browser!?!?! I working... for
Runtime.getRuntime().exec("...........");
I came across the
java code.... Rather i want to open it in my
browser(Mozilla/IE) itself. Kindly provide me
Opening a URL from an Applet
used for
opening url
from an applet. This
program is using two functions in which...
Opening a URL
from an Applet
 ... window
from an applet. This
program shows that
how a url is opened in same
Java - Opening a url in new window from an applet
Java -
Opening a url in new window
from an applet
 ... will open new
browser window and then show you the web page.
Opening a new... how to open a new window
from an applet. You can use the code given
connect ftp from java program
connect ftp
from java program Hi,
I need to connect to the ftp and get the files through a
java program..
I wrote the following code...
import...)
the same worked me well when i entered in the
browser...
whats the problem
connect ftp from java program
connect ftp
from java program Hi,
I need to connect to the ftp and get the files through a
java program..
I wrote the following code...
import...)
the same worked me well when i entered in the
browser...
whats the problem
Applet : Java Glossary
;
An applet in
java programming language is a small
program that
only runs...) provided by
java, the programmer needs to
create
only a single
program, which.... A user
only
requires an applet's Web page to download and execute the applet.
Java
receive message from mobile to java program
receive message
from mobile to
java program i got a code to receive message....but wen i receive it its showing a string which is not readable...
if possible please edit dis code to retreive the origianl string message....
here
how to run a applet from browser
how to run a applet
from browser hi,
iam sending the code of an applet.
it is working in cmd prompt,but not working
from browser.
<APPLET CODE... error.
plz suggest me the related code to execute
from browser.
import
Compiling and Running Java program from command line
Compiling and Running
Java program from command line - Video tutorial
that explains you all steps necessary to compile and run the
Java program from
dos... of compiling and running
java
program from command line. We have also video
The Java Applet Viewer
;
Applet viewer is a command line
program to run
Java applets... to the system and then the
Java Virtual Machine (JVM) of the
browser executes... different
from a Web
browser, though they are logically same.
The Applet viewer
Opening Notepad
Opening Notepad Sir/madam
I want to open notepad
from java applications and save the contents on it. Can someone please help me to do...};
Runtime.getRuntime().exec(commands);
}
Java Create
How to play only video file from any link
How to play
only video file
from any link Hi Friends Please Help Me.
My requirement is to play
only videos
from any webpages(ITS NOT A ABSOLUTE PATH)[IF I PASTE any VRL---,IT HAS TO BE PLAY IN ANY CONTROL] how it possible
browser
browser how to make a
browser
Browser making by java coding
Browser making by
java coding import javax.swing.*;
import...*;
import java.io.*;
public class
Browser extends JFrame implements...[])
{
if(args.length==0)
new
Browser ("http:google.com"#;
else
new
Browser#args#0
Java Web Browser Problem
Java Web
Browser Problem Hello
When run my web
browser....");
setTitle("NextVision
Browser");
setSize(600,400);
Container...) {
JOptionPane.showMessageDialog(null, "
Program Under Progress
The Java Applet Viewer
;
Applet viewer is a command line
program to run
Java applets... to the system and then the
Java Virtual Machine (JVM) of the
browser executes... different
from a Web
browser, though they are logically same.
The Applet viewer runs