Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing key event from applet to the browser 1

Status
Not open for further replies.

rm2000

Programmer
May 8, 2002
7
US
I have a keyboard handler in a java applet.
How do I send certain key event to the web browser (where java applet is loaded) so that the key is processed by the browser even though the focus is with the applet.
Fro example, I want to pass on the event for F5 key from the keylistener in applet to the browser (IE/NS7) so the page is refreshed.

Thanks in advance.
 
Suppose you a hmtl file called test.htm with an applet. You can use applet to call a javascript function in test.htm
My example show you to use java to a javascript function to open a new window. You may use javascript to reload a html page within a frame.
***test.htm
<html>
<head>
<script lang=&quot;JavaScript&quot;>
function myopen()
{
window.open(&quot;test.htm&quot;)
}
</script>
</head>
<applet code=JSPopup width=300 height=300>
<PARAM NAME=&quot;MAYSCRIPT&quot; VALUE=&quot;TRUE&quot;>
</applet>
</html>
//JSPopup.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import netscape.javascript.*;

public class JSPopup extends Applet {
public void init() {
final TextArea ta = new TextArea();
Button button = new Button(&quot;Launch&quot;);
ActionListener listener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*
String htmlText = ta.getText();
JSObject topWindow =
JSObject.getWindow(JSPopup.this);
Object args[] = new Object[3];
args[2] = &quot;width=300,height=300,&quot; +
&quot;location=0,menubar=0,status=0,toolbar=0&quot;;
JSObject popupWindow =
(JSObject)topWindow.call(&quot;open&quot;, args);
JSObject document = (JSObject)
popupWindow.getMember(&quot;document&quot;);
args = new Object[] {htmlText};
document.call(&quot;write&quot;, args);
*/
JSObject jsobject = JSObject.getWindow(JSPopup.this);
Object args[] ={ &quot;&quot; };

jsobject.call (&quot;myopen&quot;, args);
}
};
button.addActionListener(listener);
setLayout(new BorderLayout());
add(ta, BorderLayout.CENTER);
add(button, BorderLayout.SOUTH);
}
}

You will need JSobject from
The following links show you how to use JSobject


To load page with javascript Please give me credit if you think this reply is useful.
 
Thanks a lot prosper. I'll see how I can invoke default key behaviors with in the browser using javascript now but your reply is very helpful. A star for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top