【问题标题】:Running JQuery script in SWT browser在 SWT 浏览器中运行 JQuery 脚本
【发布时间】:2014-12-12 14:40:44
【问题描述】:

我正在开发一个带有嵌入式 SWT 浏览器的 Java 应用程序。我想在 SWT 浏览器上运行一个 jquery 脚本。我已将 jquery 库文件放在项目的 src 文件夹中。这是程序。

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



    }

}

【问题讨论】:

    标签: java jquery eclipse browser swt


    【解决方案1】:

    问题是因为脚本无法找到 lib>这里有一个解决方案Show local HTML file with JavaScript in SWT Browser widget in RAP

    我刚刚通过将 src 更改为

    解决了这个问题
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    

    从 W3Schools.com “试用编辑器”获取此链接

    【讨论】:

      猜你喜欢
      • 2014-04-23
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 2015-03-03
      • 1970-01-01
      相关资源
      最近更新 更多