I am developing an Java application with an embedded SWT browser in it.I want to run a jquery script on the SWT browser.I have placed by jquery library file in the src folder of the project.And here is the program.
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.AuthenticationEvent;
import org.eclipse.swt.browser.AuthenticationListener;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.ProgressEvent;
import org.eclipse.swt.browser.ProgressListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
public class Dummy3 {
static int x=1;
public static void main(String args[])
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
//static int x=1;
final Browser browser = new Browser(shell, SWT.NONE);
final String s= "<html>"+
"<head>"+
"<title>The jQuery Example</title>"+
"<script type=\"text/javascript\""+
"src=\"jquery-2.1.1.min.js\"></script>"+
"<script type=\"text/javascript\" language=\"javascript\">"+
// <![CDATA[
"$(document).ready(function() {"+
"$(\"div\").click(function() {"+
"alert(\"Hello world!\");"+
"});"+
"});"+
// ]]>
"</script>"+
"</head>"+
"<body>"+
"<div id=\"newdiv\">"+
"Click on this to see a dialogue box."+
"</div>"+
"</body>"+
"</html>" ;
browser.setText(s);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}