Hi All, I want to open a URL in IE from my Java Swing application running in Wiindows. I am using the below code.
public static boolean openInBrowserKioskMode(String url){ String os = System.getProperty("os.name").toLowerCase(); Runtime rt = Runtime.getRuntime(); try{ if (os.indexOf( "win" ) >= 0) { rt.exec( "rundll32 url.dll,FileProtocolHandler " + url); } }catch (IOException e){ e.printStackTrace(); return false; } return true; }
As per the above code, IE window is opening. But I want to open the IE window in Kiosk mode or without address bar, foward/back buttons, etc. Please help me to resolve this problem
Thanks & Regards, Abhijith
Here is a simple example of opening IE in swing application.
class OpenBrowser { public static void main(String[] args) { String browserPath = "C:/Program Files/Internet Explorer/IEXPLORE.EXE"; String url = "www.roseindia.net"; try { String[] b = {browserPath, url}; Runtime.getRuntime().exec(b); } catch (Exception exc) { exc.printStackTrace(); } } }
Here is a simple example of opening browser in swing application.
1)OpenBrowser.java
import javax.swing.*; import java.lang.reflect.Method; public class OpenBrowser { public static void openURL(String url) { String osName = System.getProperty("os.name"); try { if (osName.startsWith("Windows")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); else { String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String browser = null; for (int count = 0; count < browsers.length && browser == null; count++) if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0) browser = browsers[count]; Runtime.getRuntime().exec(new String[] {browser, url}); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n" + e.getLocalizedMessage()); } } }
2)Browser.java
import javax.swing.*; import java.awt.event.*; public class Browser { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); final JTextField url =new JTextField(20); JButton button = new JButton("Open Browser"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OpenBrowser.openURL(url.getText().trim()); } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.add(new JLabel("URL:")); panel.add(url); panel.add(button); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } }
Here is a simple example of opening browser in swing application.
1)OpenBrowser.java
import javax.swing.*; import java.lang.reflect.Method; public class OpenBrowser { public static void openURL(String url) { String osName = System.getProperty("os.name"); try { if (osName.startsWith("Windows")) Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url); else { String[] browsers = {"firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" }; String browser = null; for (int count = 0; count < browsers.length && browser == null; count++) if (Runtime.getRuntime().exec(new String[] {"which", browsers[count]}).waitFor() == 0) browser = browsers[count]; Runtime.getRuntime().exec(new String[] {browser, url}); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error in opening browser" + ":\n" + e.getLocalizedMessage()); } } }
2)Browser.java
import javax.swing.*; import java.awt.event.*; public class Browser { public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); final JTextField url =new JTextField(20); JButton button = new JButton("Open Browser"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OpenBrowser.openURL(url.getText().trim()); } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel.add(new JLabel("URL:")); panel.add(url); panel.add(button); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } }