Close parent window of Mozilla browser from Java

Hi All,
I want to open a URL in a controlled browser from java stand alone application. I was able to do this in Netscape of UNIX OS. The method followed is given below.
1. Launch a temporary HTML file which contains Javascript (to launch the URL in a controlled window). This is done using --- Runtime.getRuntime().exec() method.
2. Close the parent HTML file on 'onLoad' using Javascript. (self.close).
[ I tried window.close() & top.close() also.]
Now I need to support the same for "Mozilla" also. But mozilla just ignores the close() command of Javascript.
1. Is there any alternative way to close the parent window in Mozilla browser ?
2. Is there any way to close the parent window from java by using 'Process' class/ threads/ ??
3. Any other way???
Note : I am using the intermediate window for using Javascript. (controlling the browser properties). Since Java cannot communicate to Javascript directly, I am forced to have such an intermediate HTML file.
Thanks in advance.
surekha_Venugopal.

Some more details :
Mozilla browser will close a window using window.close() command, but only if the window is opened by the script. If not it will not close it.
Here, I am opening the window from Java application. That is why closure of the window is failing.
Trying to find a solution.
Regards,
Surekha_Venogopal

Similar Messages

  • Launching Browser from Java when Browser URL is very  long

    Hi,
    I am trying to launch a browser from Java.
    I am doing the following.
    String command = "cmd" + "/c" + "start" + " browserURL";
    Process p = Runtime.getRuntime()exec(command);
    Note: My browserURL is very long.
    Now the browser is invoked. But the URL shown is incomplete and hence
    browser is unable to open the required application.
    Can someone help me in this.
    One way is to increase the buffer size on the command prompt?
    Is there any java command for this?
    Is there any other way to solve this issue.
    Thanks,
    AR

    this is my second time posting this, take note of it. I can't remember where i got it from, but credits go to the person that wrote it. It has helped me out thousands of times!!!
    to use, compile, then call from your program:
    org.newio.utils.BrowserLauncher.openURL("your url here")dfwtc
    package org.newio.utils;
    import java.io.File;
    import java.io.IOException;
    import java.lang.reflect.*;
    public class BrowserLauncher
        private static int jvm;
        private static Object browser;
        private static boolean loadedWithoutErrors;
        private static Class mrjFileUtilsClass;
        private static Class mrjOSTypeClass;
        private static Class macOSErrorClass;
        private static Class aeDescClass;
        private static Constructor aeTargetConstructor;
        private static Constructor appleEventConstructor;
        private static Constructor aeDescConstructor;
        private static Method findFolder;
        private static Method getFileType;
        private static Method makeOSType;
        private static Method putParameter;
        private static Method sendNoReply;
        private static Object kSystemFolderType;
        private static Integer keyDirectObject;
        private static Integer kAutoGenerateReturnID;
        private static Integer kAnyTransactionID;
        private static final int MRJ_2_0 = 0;
        private static final int MRJ_2_1 = 1;
        private static final int WINDOWS_NT = 2;
        private static final int WINDOWS_9x = 3;
        private static final int OTHER = -1;
        private static final String FINDER_TYPE = "FNDR";
        private static final String FINDER_CREATOR = "MACS";
        private static final String GURL_EVENT = "GURL";
        private static final String FIRST_WINDOWS_PARAMETER = "/c";
        private static final String SECOND_WINDOWS_PARAMETER = "start";
        private static final String NETSCAPE_OPEN_PARAMETER_START = " -remote 'openURL(";
        private static final String NETSCAPE_OPEN_PARAMETER_END = ")'";
        private static String errorMessage;
        private BrowserLauncher()
        private static boolean loadClasses()
            switch(jvm)
            default:
                break;
            case 0: // '\0'
                try
                    Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
                    macOSErrorClass = Class.forName("com.apple.MacOS.MacOSError");
                    Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
                    Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
                    Class aeClass = Class.forName("com.apple.MacOS.ae");
                    aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
                    aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {
                        Integer.TYPE
                    appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] {
                        Integer.TYPE, Integer.TYPE, aeTargetClass, Integer.TYPE, Integer.TYPE
                    aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {
                        java.lang.String.class
                    makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] {
                        java.lang.String.class
                    putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] {
                        Integer.TYPE, aeDescClass
                    sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[0]);
                    Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
                    keyDirectObject = (Integer)keyDirectObjectField.get(null);
                    Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
                    kAutoGenerateReturnID = (Integer)autoGenerateReturnIDField.get(null);
                    Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
                    kAnyTransactionID = (Integer)anyTransactionIDField.get(null);
                    break;
                catch(ClassNotFoundException cnfe)
                    errorMessage = cnfe.getMessage();
                    return false;
                catch(NoSuchMethodException nsme)
                    errorMessage = nsme.getMessage();
                    return false;
                catch(NoSuchFieldException nsfe)
                    errorMessage = nsfe.getMessage();
                    return false;
                catch(IllegalAccessException iae)
                    errorMessage = iae.getMessage();
                return false;
            case 1: // '\001'
                try
                    mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
                    mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
                    Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
                    kSystemFolderType = systemFolderField.get(null);
                    findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] {
                        mrjOSTypeClass
                    getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] {
                        java.io.File.class
                    break;
                catch(ClassNotFoundException cnfe)
                    errorMessage = cnfe.getMessage();
                    return false;
                catch(NoSuchFieldException nsfe)
                    errorMessage = nsfe.getMessage();
                    return false;
                catch(NoSuchMethodException nsme)
                    errorMessage = nsme.getMessage();
                    return false;
                catch(SecurityException se)
                    errorMessage = se.getMessage();
                    return false;
                catch(IllegalAccessException iae)
                    errorMessage = iae.getMessage();
                return false;
            return true;
        private static Object locateBrowser()
            if(browser != null)
                return browser;
            switch(jvm)
            case 0: // '\0'
                try
                    Integer finderCreatorCode = (Integer)makeOSType.invoke(null, new Object[] {
                        "MACS"
                    Object aeTarget = aeTargetConstructor.newInstance(new Object[] {
                        finderCreatorCode
                    Integer gurlType = (Integer)makeOSType.invoke(null, new Object[] {
                        "GURL"
                    Object appleEvent = appleEventConstructor.newInstance(new Object[] {
                        gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID
                    return appleEvent;
                catch(IllegalAccessException iae)
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                catch(InstantiationException ie)
                    browser = null;
                    errorMessage = ie.getMessage();
                    return browser;
                catch(InvocationTargetException ite)
                    browser = null;
                    errorMessage = ite.getMessage();
                    return browser;
            case 1: // '\001'
                File systemFolder;
                try
                    systemFolder = (File)findFolder.invoke(null, new Object[] {
                        kSystemFolderType
                catch(IllegalArgumentException iare)
                    browser = null;
                    errorMessage = iare.getMessage();
                    return browser;
                catch(IllegalAccessException iae)
                    browser = null;
                    errorMessage = iae.getMessage();
                    return browser;
                catch(InvocationTargetException ite)
                    browser = null;
                    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
                    return browser;
                String systemFolderFiles[] = systemFolder.list();
                for(int i = 0; i < systemFolderFiles.length; i++)
                    try
                        File file = new File(systemFolder, systemFolderFiles);
    if(file.isFile())
    Object fileType = getFileType.invoke(null, new Object[] {
    file
    if("FNDR".equals(fileType.toString()))
    browser = file.toString();
    return browser;
    catch(IllegalArgumentException iare)
    browser = browser;
    errorMessage = iare.getMessage();
    return null;
    catch(IllegalAccessException iae)
    browser = null;
    errorMessage = iae.getMessage();
    return browser;
    catch(InvocationTargetException ite)
    browser = null;
    errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
    return browser;
    browser = null;
    break;
    case 2: // '\002'
    browser = "cmd.exe";
    break;
    case 3: // '\003'
    browser = "command.com";
    break;
    case -1:
    default:
    browser = "netscape";
    break;
    return browser;
    public static void openURL(String url)
    throws IOException
    if(!loadedWithoutErrors)
    throw new IOException("Exception in finding browser: " + errorMessage);
    Object browser = locateBrowser();
    if(browser == null)
    throw new IOException("Unable to locate browser: " + errorMessage);
    switch(jvm)
    case 0: // '\0'
    Object aeDesc = null;
    try
    try
    aeDesc = aeDescConstructor.newInstance(new Object[] {
    url
    putParameter.invoke(browser, new Object[] {
    keyDirectObject, aeDesc
    sendNoReply.invoke(browser, new Object[0]);
    catch(InvocationTargetException ite)
    throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
    catch(IllegalAccessException iae)
    throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
    catch(InstantiationException ie)
    throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
    break;
    finally
    aeDesc = null;
    browser = null;
    case 1: // '\001'
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    break;
    case 2: // '\002'
    case 3: // '\003'
    Runtime.getRuntime().exec(new String[] {
    (String)browser, "/c", "start", url
    break;
    case -1:
    Process process = Runtime.getRuntime().exec((String)browser + " -remote 'openURL(" + url + ")'");
    try
    int exitCode = process.waitFor();
    if(exitCode != 0)
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    catch(InterruptedException ie)
    throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
    break;
    default:
    Runtime.getRuntime().exec(new String[] {
    (String)browser, url
    break;
    static
    loadedWithoutErrors = true;
    String osName = System.getProperty("os.name");
    if("Mac OS".equals(osName))
    String mrjVersion = System.getProperty("mrj.version");
    String majorMRJVersion = mrjVersion.substring(0, 3);
    try
    double version = Double.valueOf(majorMRJVersion).doubleValue();
    if(version == 2D)
    jvm = 0;
    } else
    if(version >= 2.1000000000000001D)
    jvm = 1;
    } else
    loadedWithoutErrors = false;
    errorMessage = "Unsupported MRJ version: " + version;
    catch(NumberFormatException numberformatexception)
    loadedWithoutErrors = false;
    errorMessage = "Invalid MRJ version: " + mrjVersion;
    } else
    if(osName.startsWith("Windows"))
    if(osName.indexOf("9") != -1)
    jvm = 3;
    } else
    jvm = 2;
    } else
    jvm = -1;
    if(loadedWithoutErrors)
    loadedWithoutErrors = loadClasses();
    suck my balls

  • Easiest way to launch a link to the default browser from java?

    Is there an easy way to launch a link in the default browser from java? Ideally I would have a graphic in a cell that when clicked on would open a new window/tab in the default browser. This would be done in SWT, but it might be similar to swing, awt, etc. Any ideas?

    If you are using Java 1.5 or earlier, I found the browser launch code found here to work fairly well: http://www.centerkey.com/java/browser

  • How to create windows users and groups from Java

    Hi,
    Can any one please tell me, which Package/API will helps to create windows users and groups from Java.
    Thanks,
    M.Prem.

    You can't do it with pure Java, and it's not in the core API. You'd have to write a native function to do it, using whatever API Windows provides, and then call it with JNI. Or look for a third party native-based Java library that already does that.

  • How to close parent window when we use call method l_window_manager- create

    hi...
    how to close parent window when we use call method l_window_manager->create_external_window
    thank you.

    hi
    good
    go through this link,hope this ll help you to solve your problem
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/63a47dd9-0b01-0010-3d8e-de27242bf011
    thanks
    mrutyun^

  • Controlling a browser from java

    hello experts,
    i want to open an web dynpro URL in a browser and navigate through the URL , like putting values in the input box and click the buttons from java code .
    Actually it is exactly like an automated test tool in java to navigate and render the given web dynpro URL with the test data given.
    its very please help.
    Regards,
    Karthik

    Hello Karthik,
    I'm using Selenium to do something similar. You can find more information at http://seleniumhq.org/
    The documentation can be found at http://seleniumhq.org/documentation/ and you can find a tutorial implementation for Java at http://seleniumhq.org/documentation/tutorials/
    You can use a new Java Project to start using Selenium, just in case you feel confused.
    I've been using Selenium for some time now, you will learn some tricks during the way. And you'd probably take a look on waitForCondition function, since you'd need some calls in order to wait for webdynpro ajax requests to populate tables (before doing your assertions).
    Hope it helps.
    Regards,
    Daniel

  • How to call windows help files .hlp from Java program

    Hai all everybody
    How to call windows Help file that is xxx.hlp files from java programs
    any help great!!!!
    regards
    veeru

    How about
    Runtime.getRuntime().exec("start xxx.hlp");

  • How to open a web browser from java

    Hi
    Would anybody please help me with this. I need to open a web browser from my java app but I don't know. What method I can use?
    Thanks.
    Hung.

    You can use the Runtime class for this. It can run any command. So, you can run the .exe file of your Web browser.
    The following code will run Internet Explorer (assuming iexplorer.exe is in C:\Program Files\Internet Explorer):
    import java.lang.Runtime;
    public class Explore{
    public static void main(String[] args) {
    try{
    Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore");
    }catch (Exception e) {
    System.out.println("Exception: " + e);

  • Call Windows COM/DCOM objects from Java on Linux

    Hello, is it possible to call COM/DCOM objects running on Windows from Java on Linux machine? Thank you.

    I don't know anything about it but it looks like EZ JCom in conjunction with the included Remote Access Service does what you're after. It's not free though.
    http://www.ezjcom.com/

  • How to control browser from java program?

    I want to retrieve the url currently loaded in my default browser. How to achieve this task using java program? I dont know how to access browser using java.

    Peter__Lawrey wrote:
    Actually Desktop.open only works for downloaded pages.
    Instead you can use this to get the browser to download the page and display it.
    Desktop.getDesktop().browse(URI.create("http://www.google.co.uk"));
    First of all thanks for your reply Mr Peter__Lawrey.
    I want to just retrieve the urls loaded in the default webbrowser, not the content of the url or the task of opening the default browser with the specific url.

  • Calling Window's Dll Functions from Java

    Hello Audience,
    Is there a way to call Win32/64 based Dynamic-Link-Library functions from Java?
    Thanks,
    GenKabuki

    Yes.
    In general, if you are trying to call functions in an existing dll, you will have to write a "wrapper" dll that meets the java jni interface requires. There are tools around wich purport to generate these for you. Do a google serach; among other tools, you should turn up JACE.

  • How to invoke browser from java program in Solaris ?

    Hi all,
    Is there any way by which a browser can be opened with specific URL, from a java program in solaris OS ?
    In windows I am able to do so by using "rundll32 url.dll,FileProtocolHandler".
    Thanks,
    ngs

    Well, how is a browser normally invoked on Solaris? And have a look at JDIC, maybe it helps you.

  • Lauch IE browser from Java Application

    Hi, I am interested in launching an IE window from a Java application. Is there a way
    to accomplish this? Thanks.

    Again, any other way that allows me to start a java application and IE browser on WINDOWS2000 would be helpful too.

  • Launhing browser from java

    Hi
    I'm Launching jsp from my java code with the help of Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + strUrl); when this jsp is Launched it passes the parameters to another jsp with action property of form.and the new browser is Launched what i want to do is when this browser is launched i want to customize the browser visibility.Like hiding toollbar.setting scrollability false etc. can someone guide me how to perform this

    You need to use javaScript for this, not java, have a google, theres loads of javaScript stuff on the web.

  • Problem with opening browser from Java app.

    Hi guys, I'm not sure if this is the right place to post this, so please excuse me if I'm wrong. I'm trying to open an html page (it's a help file) from a Java application. I'm currently using java.awt.Desktop.     browse(URI uri); which gets the job done, as long as I don't pass any parameters to the page. (e.g. http://www.site.com/site.html?param1=1). Doing that gives me an IOException. Is there a way to do this without using the JNLP API?

    This is the file path copied directly from the browser's address bar:
    file:///home/riaan/EMCHelp/Help.html?page=WorkFlowActivityCategory.html"{code}
    Which causes the app to throw an exception, but when I change it to:
    {code}file:///home/riaan/EMCHelp/Help.html{code}
    it opens Help.html in the browser.  That's why I thought that it might be the query that's a problem.  Perhaps it's a simple issue of not escaping a character or something that I failed to see.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • Why can't you change the .html/.htm filetype icons for Firefox?

    **Before you read this question: NOTICE I am talking about Firefox Icons on Windows, NOT ON FIREFOX BOOKMARKS/PROGRAM!!!!! Read the question then please, please visit the link so you have a better understanding of what I'm asking with this question!!

  • Airport 4.2 update...no internet (negotiating PPPoE...)

    since i've run all the latest updates for both my OS (10.4.2 tiger) and airport 4.2 i can no longer get on the internet via my wireless airport connection. I have to connect via ethernet cable. i just keep getting the error negotiating PPPoE... scrol

  • About HRMS & Report ???

    Hi all I want to know how to (add) or linking report builded to application like HRMS .. Thank you

  • Business Logic

    HELLO, I have gotten into a unique situation while builiding a business logic for below case. Here is how the process/contracts are set up. Fields: CLAIM_ID is unique and in order of the reciept of claim. M_ID is Member_ID. Reserve_Date is when Membe

  • MacBook OS x not compatible with ipad2?

    Is my MacBook OS X nots compatible with iPad 2?  Unable to access iTunes from iPad to MacBook.