1

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();
        }



    }

}
codd
  • 55
  • 1
  • 5

1 Answers1

0

The problem is because the script is not able to locate lib>there is one solution here Show local HTML file with JavaScript in SWT Browser widget in RAP .

I have just solved this by changing src to

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Taken this link from W3Schools.com "Try Editor"

Community
  • 1
  • 1
codd
  • 55
  • 1
  • 5