Hi, I have a java code which basically call a JavaScript to open a new window and it and it will give you the focus on new window.
Code:
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.Graphics;
import netscape.javascript.JSObject;
public class Test extends Applet implements MouseListener
{
public void start()
{}
public void stop()
{}
public void init()
{
addMouseListener(this);
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{}
public void mouseClicked(MouseEvent e)
{
JSObject window = JSObject.getWindow(this);
Object[] args = {""};
window.call("jsfunction", args);
}
public void mouseEntered(MouseEvent e)
{}
public void mouseExited(MouseEvent e)
{}
public void mousePressed(MouseEvent e)
{}
public void mouseReleased(MouseEvent e)
{}
}
The code of java script is as follows:
Code:
<html>
<head>
<title>Test the code </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
<!--
var window = null;
function jsfunction(strURL)
{
var width = 800;
var height = 600;
var url = "http://www.techarena.in";
a = (screen.availHeight - height)/2;
b = (screen.availWidth - width)/2;
window = window.open(url,'Window','width='+width+',height='+height+',screenX='+a+',screenY='+b+',top='+b+',left='+a);
window.focus();
}
-->
</script>
</head>
<body>
<applet type="applet" code="TestApplet" name="TestApplet" width="100%" height="100%">
</applet>
</body>
</html>
Bookmarks