在SWT中使用受控嵌入式浏览器
有谁知道如何使用SWT中的“受控嵌入式浏览器”,它允许页面操作?我只能找到有关如何使用普通SWT浏览器的信息,但我需要能够与加载的页面进行交互。谢谢。像这样 - http://publib.boulder.ibm.com/infocenter/btt/v7r0/index.jsp?topic=%2Fcom.ibm.btt.application_presentation.doc_7.0%2Fdoc%2Freference%2Frichclient%2Fcontrolembededbrowser.html - 但没有关于如何发起这样的课程的指导。在SWT中使用受控嵌入式浏览器
这里是Eclipse SWT snippets website
的example另外这个帖子可能给你这方面的一些见解。 Using Java Objects in JavaScript in Eclipse SWT Browser Control
要将Java对象从Eclipse公开到JavaScript,您需要创建一个扩展BrowserFunction的类。这个类的构造函数有两个参数;第一个是浏览器实例,第二个是功能,将在运行SWT浏览器控件的JavaScript代码可用...的名字......
代码片断
BrowserFunction:
import java.io.File;
import org.eclipse.swt.browser.Browser; import org.eclipse.swt.browser.BrowserFunction;
public class ListFilesFunction extends BrowserFunction {
Browser browser = null;
String functionName = null;
public ListFilesFunction(Browser browser, String name) {
super(browser, name);
this.browser = browser;
this.functionName = name;
}
public Object function (Object[] args)
{
if (args.length == 0)
browser.execute("alert('Function " +
functionName + " requires one argument - parent folder path');");
File file = new File(args[0].toString());
if (!file.exists())
browser.execute("alert('Folder " + args[0] +
" does not exist');");
if (!file.isDirectory())
browser.execute("alert('Path " + args[0] + " must be a folder');");
return file.list();
}
}
准此功能的浏览器控制
public class View extends ViewPart
{
Browser browserCtl = null;
...
public void createPartControl(Composite parent) {
...
browserCtl = new Browser(parent, SWT.None);
new ListFilesFunction(browserCtl, "getFiles");
...
}
...
}
援引JAV此功能aScript:
<html>
<head>
<script type='text/javascript'>
files = getFiles("c:/");
for (i = 0; i < files.length; i++)
{
document.writeln(files[i] + "<br>");
}
</script>
</head>
<body>
</body>
</html>
对不起,这是很晚,但谢谢。 – 2013-09-03 14:26:03
没关系,我的回答也晚了:),但希望这可以作为其他人的参考 – didxga 2013-09-04 03:16:53