日期:2014-05-20  浏览次数:20772 次

关于Java内嵌浏览器的问题
现在要做一个java应用程序。这个程序中要用到内嵌的浏览器,并且希望在用户点击浏览器中的页面元素时,java程序中能够获取到对应事件,并在从该事件中得到是网页上的(也就是DOM树上的)哪个元素。

请大家推荐哪些内嵌浏览器可以满足这样的需求?
并告知使用的难易程度,以及是否要收费等服务信息?

------解决方案--------------------
友情帮顶,不求分。
------解决方案--------------------
谷歌浏览器内嵌框架是一款免费插件,可在 Internet Explorer 中使用新式的 HTML5 网络应用程序
------解决方案--------------------
方法一、


基于eclipse swt做java浏览器内嵌等功能
swt-3.5M4-win32-win32-x86.zip 包下载地址: http://download.csdn.net/source/921856

Java code
import java.util.ArrayList;  
  
import org.eclipse.swt.SWT;  
import org.eclipse.swt.browser.Browser;  
import org.eclipse.swt.browser.OpenWindowListener;  
import org.eclipse.swt.browser.VisibilityWindowListener;  
import org.eclipse.swt.browser.WindowEvent;  
import org.eclipse.swt.events.DisposeEvent;  
import org.eclipse.swt.events.DisposeListener;  
import org.eclipse.swt.graphics.Image;  
import org.eclipse.swt.graphics.Point;  
import org.eclipse.swt.layout.FillLayout;  
import org.eclipse.swt.widgets.Display;  
import org.eclipse.swt.widgets.Event;  
import org.eclipse.swt.widgets.Listener;  
import org.eclipse.swt.widgets.Shell;  
  
public class BrowserTest1 {  
static final ArrayList urls = new ArrayList(); // @jve:decl-index=0:  
static boolean canRemove = false;  
public static void main(String[] args) {  
      Display display = new Display();  
      Shell shell = new Shell(display);  
      shell.setText("jog36行业招聘");  
      Image image = new Image(shell.getDisplay(), "Favicon.ico");  
      shell.setImage(image);  
      shell.setLayout(new FillLayout());  
      Browser browser = new Browser(shell, SWT.NONE);  
      initialize(display, browser);  
      shell.open();  
      browser.setUrl("www.job36.com");  
      while (!shell.isDisposed()) {  
        if (!display.readAndDispatch())  
          display.sleep();  
      }  
      display.dispose();  
}  
  
static void initialize(final Display display, Browser browser) {  
      browser.addListener(SWT.MouseDown, new Listener() {  
        public void handleEvent(Event event) {  
          System.out.println("event.time:" + event.time);  
        }  
      });  
      browser.addOpenWindowListener(new OpenWindowListener() {  
        public void open(WindowEvent event) {  
          // Embed the new window  
          final Shell shell = new Shell(display);  
          shell.setText("New Window");  
          shell.setLayout(new FillLayout());  
          final Browser browser = new Browser(shell, SWT.NONE);  
          initialize(display, browser);  
          event.browser = browser;  
          event.display.asyncExec(new Runnable() {  
              public void run() {  
                String url = browser.getUrl();  
                System.out.println(url);  
                System.out.println(browser.getText());  
                if (urls.contains(url)){  
                  //flag to chek if the window is closed automatic  
                  canRemove = false;  
                  shell.close();  
                }  
                else{  
                  canRemove = true;  
                  urls.add(url);  
                }  
                 
              }  
          });  
        }  
      });  
      browser.addVisibilityWindowListener(new VisibilityWindowListener() {  
        public void hide(WindowEvent event) {  
          Browser browser = (Browser) event.widget;  
          Shell shell = browser.getShell();  
          shell.setVisible(false);  
        }  
  
        public void show(WindowEvent event) {  
          Browser browser = (Browser) event.widget;  
          Shell shell = browser.getShell();  
          if (event.location != null)  
              shell.setLocation(event.location);  
          if (event.size != null) {  
              Point size = event.size;  
              shell.setSize(shell.computeSize(size.x, size.y));  
          }  
          if (event.addressBar || event.menuBar || event.statusBar  
                || event.toolBar) {  
              // Create widgets for the address bar, menu bar, status bar and/or tool bar  
              // leave enough space in the Shell to accomodate a Browser of the size  
              // given by event.size  
          }  
          shell.open();  
        }  
      });  
      browser.addDisposeListener(new DisposeListener(){  
        public void widgetDisposed(DisposeEvent event){  
          Browser browser = (Browser) event.widget;  
          if (canRemove)  
              urls.remove(browser.getUrl());  
          Shell shell = browser.getShell();  
         // shell.close();  
        }  
      });  
}  
  
}