If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Can't use JavaScript focus() from an applet

RESOLVED WORKSFORME

Status

SeaMonkey
General
RESOLVED WORKSFORME
12 years ago
10 years ago

People

(Reporter: olivier.etienne, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915

Under Mozilla or Firefox, I can't open a page wich contains the javascript instruction : self.focus().

To reproduce the problem :
step 1 : Applet is started
step 2 : A browser is opened
step 3 : I display a modal JDialog from the applet
step 4 : From this modal JDialog, I try to reuse the browser opened at step 2 to load a page wich contains self.focus().

The second time I try to use the browser (step 4), its window is cleared and the javascript console contains :
Error: uncaught exception:
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)"
location: "JS frame :: file:///C:/getFocus.html :: <TOP_LEVEL> :: line 2" data: no]

Here is the code of my applet :

import java.awt.event.*;
import java.net.*;
import javax.swing.*;
 
/**
 * applet
 */
public class MainApplet extends JApplet {
        // -->step 1
	public void start() { 
		openBrowserWithFocus();	 // --> step 2
		MyDialog dlg = new MyDialog();
		dlg.show();         // -->step 3
	}
 
	/**
	 * Open a web page that contains self.focus();
	 */
	protected void openBrowserWithFocus() {
		try {
			getAppletContext().showDocument(new URL("file:///C:/getFocus.html"), "_NAME_");
		} catch (MalformedURLException e) {}		
	}
	
	class MyDialog extends JDialog implements ActionListener{
		/**
		 * Build a modal dialog with 1 button
		 */
		public  MyDialog (){
			setModal(true);
			JButton openBrowser = new JButton("open with focus");
			openBrowser.addActionListener(this);
			getContentPane().add(openBrowser);
			pack();
		}
		
		/**
		 * Manage click on button 
		 */
		public void actionPerformed(ActionEvent e_) {
			openBrowserWithFocus();        // -->step 4
		}
	}
}



Here is the code of the page I try to load :

<SCRIPT>
self.focus();
document.write("<H1>I got the focus !</H1>");
</SCRIPT>

Code of the applet page : 
<HTML>
<APPLET MAYSCRIPT=true 
		CODE="MainApplet.class"
		ARCHIVE="MainApplet.jar"
</APPLET>
</HTML>

Reproducible: Always

Steps to Reproduce:
1. Compile the applet : javac MainApplet.java
2. Generate the jar : jar cvf MainApplet.jar *.class
3. Deploy MainApplet.jar and the applet start page in a same directory
4. Copy getFocus.html on C:\
5. Load the applet
6. Clic on the button "open with focus"

Actual Results:  
The browser display a white page (without <H1>I got the focus !</H1>). 
It doesn't go to foreground 
The javascript console contains : 

Error: uncaught exception:
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)"
location: "JS frame :: file:///C:/getFocus.html :: <TOP_LEVEL> :: line 2" data: no]


Expected Results:  
The page go the the foreground and contains : I got the focus
(Reporter)

Comment 1

12 years ago
The problems occurs also under Firefox

Updated

12 years ago
Severity: critical → normal
Summary: Crash using JScript focus() from an applet → Can't use JavaScript focus() from an applet

Comment 2

12 years ago
Olivier, what is the value of 
Edit/Preferences.../Advanced category/Scripts & plugins/Allow scripts to:/Raise or lower windows checkbox?
If that checkbox is unchecked, then please check it and try again. (I don't think this will help but who knows).

The code of the page you try to load seems clearly insufficient to me.

Olivier, can you make your MainApplet.jar file available somewhere or try to attach it in this bug (Choose content-type binary file and zip it) or even send it to me in an email in an attachment and I'll do a better code of webpage for you so that we can better test, verify and confirm the existence of a bug here.

Thanks

P.S.; One last thing. When testing a page, make sure you're using a recent trunk nightly build. rv1.7.12 Gecko/20050915 is a 3 months old release. 
"be sure that you've reproduced your bug using a build released within the past three days. Our development process moves at lightning speed, and the bug you've found may already have been fixed."
http://www.mozilla.org/quality/bug-writing-guidelines.html
Also, if the problem occurs in Firefox, please mention the version and build date.
(Reporter)

Comment 3

12 years ago
> Olivier, what is the value of 
> Edit/Preferences.../Advanced category/Scripts & plugins/Allow scripts to:/Raise
> or lower windows checkbox?
> If that checkbox is unchecked, then please check it and try again. (I don't
> think this will help but who knows).

The checkbox is checked.


> The code of the page you try to load seems clearly insufficient to me.
> 
> Olivier, can you make your MainApplet.jar file available somewhere 

All files are available at the following URLs :
http://www.chez.com/oetienne/bug323285/TestApplet.html
http://www.chez.com/oetienne/bug323285/GetFocus.html
http://www.chez.com/oetienne/bug323285/MainApplet.jar
http://www.chez.com/oetienne/bug323285/MainApplet.java

I've changed TestApplet.html and MainApplet.java in order to pass the URL of GetFocus.html as a parameter of the applet.


> P.S.; One last thing. When testing a page, make sure you're using a recent
> trunk nightly build. rv1.7.12 Gecko/20050915 is a 3 months old release. 
Ok, I will try it on thursday (I'm out of office)

> "be sure that you've reproduced your bug using a build released within the past
> three days. Our development process moves at lightning speed, and the bug
> you've found may already have been fixed."
> http://www.mozilla.org/quality/bug-writing-guidelines.html
> Also, if the problem occurs in Firefox, please mention the version and build
> date.
> 

Comment 4

12 years ago
> All files are available at the following URLs :
> http://www.chez.com/oetienne/bug323285/TestApplet.html
> http://www.chez.com/oetienne/bug323285/GetFocus.html
> http://www.chez.com/oetienne/bug323285/MainApplet.jar
> http://www.chez.com/oetienne/bug323285/MainApplet.java

Etienne, as far as I can figure this out, the focus() command is called and accomplished when the popup blocker is desactivated. Now, if you want further investigation, then you'll need to create a *_reduced_* and *_simplified_* testcase (1) where 
- the problem clearly exists in a recent build
- nothing (like advertisement, a popup, a popunder like http://pub.chez.com/t_popunder_default.html, a dynamically created frames/frameset, etc.) might interfere or corrupt the testcase
- http://www.chez.com/oetienne/bug323285/MainApplet.jar 
and
http://www.chez.com/oetienne/bug323285/MainApplet.java
are made available and downloadable separately.

As it stands, I can not reproduce the problem and I get the expected results.

WORKSFORME

(1) What is a Simplified Test Case, and How Do I Make One?
http://www.mozilla.org/newlayout/bugathon.html#testcase
Whiteboard: WFM

Comment 5

12 years ago
No reply for 2 weeks. I am assuming that there is no problem.

Resolving as WORKSFORME
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → WORKSFORME
Whiteboard: WFM
(Reporter)

Comment 6

12 years ago
(In reply to comment #5)
> No reply for 2 weeks. I am assuming that there is no problem.
> 
> Resolving as WORKSFORME
> 

There is no response because : 
1- my application is already minimal. I can't see how to minimize it more.
2- I don't have any web site to publish an online test version of my application.

Olivier
Status: RESOLVED → UNCONFIRMED
Resolution: WORKSFORME → ---

Comment 7

12 years ago
With SeaMonkey 1.0 and current trunk, nothing happens when I hit the button.  With Mozilla 1.7.12, I get a new window with "I got focus" when loading the java applet.  If I close it and hit the button again, I get another window.  If I enable popups, I get the same behavior as with Mozilla.

If I switch the pref to open new links in the same window (instead of a new window or a new tab), the button works as you expect.

Do you see this problem with a clean profile?

Comment 8

10 years ago
Given that so much time passed I'm not surprised that the test URLs given in comment 3 don't exist any more. As nobody but the reporter managed to reproduce while they were there this seems like WFM.

If this is still a problem, it would be good to attach a testcase to this bug so that it doesn't vanish any more and try with a clean profile as suggested in comment 7.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 12 years ago10 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.