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.

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









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
opening internet browser in java program - Swing AWT
opening internet browser in java program  i want a code to open the internet browser in swing program using JFrame.  Hi Omkar, Use...) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n" + e.getLocalizedMessage
Advertisements
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
Java - Opening a url in new window from an applet
Java - Opening a url in new window from an applet       This is the example of opening a url from an applet. This program shows that how a url is opened in a new document or browser
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 IE from Java Swing Application in Kiosk mode
Opening IE from Java Swing Application in Kiosk mode  Hi All, I want to open a URL in IE from my Java Swing application running in Wiindows. I am...(); } } }   Here is a simple example of opening browser
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
features have been used for opening url from an applet. This program is using two... Opening a URL from an Applet     ... window from an applet. This program shows that how a url is opened in same
download a file from browser - Java Beginners
download a file from browser  How to download a file from browser and save it in local path
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
Help with opening a text file upon closing a program.
Help with opening a text file upon closing a program.  I need some helping in figuring out something I want to do. I have this program... that file to open whenever the user exits the program. My code so far
WAS server configuration from JAVA program
WAS server configuration from JAVA program  How to get web sphere server status like heap,connection pool properties,stall counts etc. from a java applciation
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i... username,password two times it opens only one time 2.i write code for tree node
difference from browser to browser - JSP-Servlet
difference from browser to browser  I am developing a project in jsp. When browse in mozilla it works good and when I open it with IE there is a difference how to overcome this problem.Thanks in advance
regarding connectivity program only - JDBC
regarding connectivity program only  can u give me code regarding .. that i had created student data base with his name and subject marks resp ... i...("Disconnected from database"); } catch (Exception e) { e.printStackTrace
regarding connectivity program only - JDBC
regarding connectivity program only  can u give me code regarding .. that i had created student data base with his name and subject marks resp ... i use html in front end ...that there r options like 1.name---------- 2.sub1
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
opening new window - Java Beginners
opening new window  Hi All, I have two classes with me , lets say A and B.when I press a button in class A , the class B should open in a new window.i.e., I want to know, how a new window(B) can be opened by clicking a button
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
Error Opening File - Java Interview Questions
Error Opening File  Dear, Please if help me to resolve this problem. I have an application in java that works correctly under Eclipse... this generated file, a message was displayed: Error opening file. But If I
how can i define only one method from the interface. - Java Beginners
how can i define only one method from the interface.  If i am having an interface with 3 methods(declaration) . If i want to use only one method for defining without defining the other two methods. if it is possible then tell me
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
Code for opening a new mail from the default mail box and copy the database contents
Code for opening a new mail from the default mail box and copy the database contents  Guys, here is how it goes when i click on a button say "mail", the code fetches the receipients, subject and the body of the mail from database
How to create one xml file from existing xml file's body?
How to create one xml file from existing xml file's body?  Hi, i'm working with content optimization system.I want to know how we can take all data from an xml doc's body to develope another xml with that content.I'm using JDOm
How to launch my web application from my desktop without opening Netbeans IDE everytime i run the application?
How to launch my web application from my desktop without opening Netbeans IDE... dont want all these steps, so i knw that java application can be launched using Java Web Start but dont knw abt web application, Is there any way to do
to retrieve message body - Java Beginners
using mysql. dbfile system is to store headers in database and message body in file system . i retrieved message contents like from :, to :, delivered... message body in file system . thanks
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW - Java Beginners
JAVA SCRIPT CODE FOR OPENING A WEBSITE IN A NEW WINDOW   PLS TELL ME? HOW CAN I DEFINE A WINDOW.OPEN FUNCTION WITHIN ANOTHER FUNCTION e.g... DATA, IT MUST OPEN A WEB SITE IN A NEW WINDOW. SPECIFICATION:MAKING ONLY "1
java program to insert data into a file and count the number of words from the file???????
java program to insert data into a file and count the number of words from the file???????  java program to insert data into a file and count the number of words from the file
Connect a linux machine from linux using java program without password
Connect a linux machine from linux using java program without password  Connect a linux machine from linux using java program without password. Can anyone help me
java program to read multiple files from a directory and display them on a jframe
java program to read multiple files from a directory and display them on a jframe  hi guys i want to write a java program that will read all files in a directory and display them one by on on a jframe on jpanel with specific key
how to write to java program to get the particular data from the website
how to write to java program to get the particular data from the website   i have to get the particular data by selecting the just numbers.. from the site .. how to get the ful details from the website by clicking the number
how to execute a unix shell script from a java program
the script name from a java code .once you execute this java program...how to execute a unix shell script from a java program  well , i am facing this problem.. i have tried a few sample codes but there isn't any
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
How to open a window from a java program (from code)[ (onclick of something text )]
How to open a window from a java program (from code)[ (onclick of something text )]  When I download the code an put it in Eclipse, the applet is run, but on click of the button displayed in the applet, a new window with google
browser
browser  how to make a browser
Toolbar to a browser - Java Beginners
to display toolbar on the browser? Thanks  I want to create a website's toolbar from scarch and wanted to konw.. which is the evfficent way to create... browser, some site ask us to download the application and install it. so i wanted
Second tab should only show selected products from first tab
Second tab should only show selected products from first tab  In the javascript, From the comment ââ?¬Â? // live update of how many circlesââ?¬Â... to feature, and it will change the template accordingly. From there I get
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
Updating rows who has same id with different values for each row from java program
) with "lalitha" as a value for sname column from java program. Same for records with sid...Updating rows who has same id with different values for each row from java... 30 Folllowing is my requirement: If multiple rows have same sid then only we
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
The Java Applet Viewer
is a command line program to run Java applets. It is included in the SDK. It helps you... and then the Java Virtual Machine (JVM) of the browser executes that code and displays the output.. So for running the applet,  the browser should be Java enabled
browser
in the swing because I am working on my project Browser and one more problem is that when I entered the URL then some page open which made in java and the page
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
Java Swing Open Browser
Java Swing Open Browser Java provides different methods to develop useful... that will open the specified url on the browser using java swing. This example will really... (Exception e) { JOptionPane.showMessageDialog(null, "Error in opening browser
list files only - Java Beginners
list files only  i have to list only files and number of files in a directory? i use list() method but it returns both files and directories in parent directory.are there any specific methods that show only files? are file

Ads