在SWT浏览器中运行JQuery脚本 [英] Running JQuery script in SWT browser

查看:186
本文介绍了在SWT浏览器中运行JQuery脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有嵌入式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 = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
// static int x = 1;
final浏览器浏览器=新浏览器(shell,SWT.NONE);


final String s =< html>+
< head>+
< title> jQuery示例< / title> +
< script type = \text / javascript\+
src = \jquery-2.1.1.min.js\>< /脚本>+

< script type = \text / javascript\language = \javascript\>+
//<![ CDATA [
$(document).ready(function(){+
$(\div \)。click(function(){+
alert (\Hello world!\);+
});+
});+
//]]>
< / script>+

< / head>+
< body>+
< div id = \\newdiv\>+
点击此处查看对话框。+
< / div>+
< / body>+
< / html> ;

browser.setText(s);


shell.open();

while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}



}

}


解决方案

问题是因为脚本无法找到lib>这里有一个解决方案在RAP中的SWT Browser小部件中显示使用JavaScript的本地HTML文件



我刚刚通过将src更改为

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

从W3Schools.com获取此链接Try Editor


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



    }

}

解决方案

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"

这篇关于在SWT浏览器中运行JQuery脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆