United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6776124 Opening a new browser window via javascript creates the window behind current
JDK-6776124 : Opening a new browser window via javascript creates the window behind current

Details
Type:
Bug
Submit Date:
2008-11-25
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2010-05-28
Component:
deploy
OS:
windows_2003,windows_xp
Sub-Component:
plugin
CPU:
x86,generic
Priority:
P3
Resolution:
Won't Fix
Affected Versions:
6,6u10,6u11,6u21
Fixed Versions:
6-pool

Related Reports
Duplicate:
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP SP3
I have been able to replicate this using Internet Explorer, versions 6 and 7.  When using Firefox 3 there is no issue.

A DESCRIPTION OF THE PROBLEM :
Our application makes several calls from our applet to javascript functions defined on the hosting jsp page.

One of the things these javascript functions do it to open a new browser window to navigate to different parts of the application (using javascript window.open()).

In previous versions of the plugin these opened windows were created on top of the window hosting the applet.  Since 6u10 the windows appear underneath the current window.  Unless the user notices a new window has appeared on the taskbar they do not know something has happened.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create an applet which calls a javascript function using JSObject.
Define a javascript function which uses window.open to open a new browser window.

Run applet, calling javascript function.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
New browser window appears on top of current window.
ACTUAL -
New browser window appears underneath current window.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
applet code as follows:

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

import netscape.javascript.JSObject;

public class TestApplet extends JApplet {

    public void init() {
        super.init();
        
        Runnable r = new Runnable() {
            public void run() {
                createGUI();
            }
        };
        try {
            SwingUtilities.invokeAndWait(r);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void createGUI() {
        getContentPane().setLayout(new FlowLayout());
        JButton button = new JButton("click me");
        button.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e) {
               callJS();
           }
        });
        getContentPane().add(button);
    }
    
    public void callJS() {
        JSObject.getWindow(this).call("myJSFunction", null);
    }
}


html code as follows

<html>
<head>
</head>

<script type="text/javascript">
function myJSFunction() {
  window.open("http://java.sun.com", "_blank", "toolbar=no, menubar=no, scrollbars=yes, resizable=yes, status=yes, location=no");
}
</script>

<body>
<applet height="100%" width="100%" code="TestApplet" archive="." mayscript>
</applet>

</body>

</html>

---------- END SOURCE ----------

Release Regression From : 6
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
EVALUATION

After a pretty long investigation on various ways around this problem, it turns out there is no acceptable solution. Essentially the issue is that a WM_KILLFOCUS event is not received by plugin. In effect, there is nothing we can do without that message. It is not being sent by windows/IE.

AWT PDE, plugin PDE and sustaining agree that this seems to be a side effect of the separate process nature of plugin2. Essentially IE is a background process, and when it opens a new window through a javascript call, it can't steal focus from the current foreground process. (which is the java applet)

The only real workaround is to use the AppletContext.showDocument() method. Note, currently (see bug 6946479) this method only works for well known targets. (_blank etc. as set out in the API) as opposed to named targets. (custom target names) This issue is being worked on. 

I'm closing as "Will not fix" but in reality, as far as plugin2 is concerned, it should be "Can not fix".
                                     
2010-05-28



Hardware and Software, Engineered to Work Together