2012-03-28 26 views
0

有誰知道如何使用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中使用受控嵌入式瀏覽器

回答

3

這裏是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> 
+0

對不起,這是很晚,但謝謝。 – 2013-09-03 14:26:03

+0

沒關係,我的回答也晚了:),但希望這可以作爲其他人的參考 – didxga 2013-09-04 03:16:53