Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Opening a browser only with body from a java program

Have Programming Question? Ask it here!
 
 
 


suresh anugandula
Opening a browser only with body from a java program
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners


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.


Advertisement
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
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
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 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 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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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...) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n
JSF imple using menus,header,body - Java Server Faces Questions
JSF imple using menus,header,body  Hi All, Could you please provied an examples of JSF implementation of Menus(alist two menusitmes),header,body and footer.   Hi Friend, Please visit the following link
BODY in HTML
BODY in HTML  What is BODY in HTML document
browser
browser  how to make a browser
Body Mass Index (BMI)
Java: Body Mass Index (BMI) The Body Mass Index program is divided into two files, the main program... with only a main program in it is a good way to clearly separate creation of the window
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
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
Browser tire - Java Interview Questions
Browser tire  If we use multithreading in my application then which tire is needed on clients browser so that application run successfully? Plz help me ass soon as possible
browser
browser  how to add menu items in the menu in java swing through java coding
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
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
Cross platform browser question - Java Beginners
Cross platform browser question  Can you tell me what this is specifially asking for? I have my program that works fine, but the instructor said...-browser (works in Firefox and MS IE) web page using anonymous JS methods
Embed Default Browser within Java Application
Embed Default Browser within Java Application  After some googling i... to embed browser with or without using Netbeans I ve already tried this 2 minutes Browser But i m getting the error in netbeans as : isDefaultBrowserMozilla
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
Advertisements
 

 

 

DMCA.com