2015-02-09 53 views

回答

0

當然,看看廚房水槽演示樣本。

通常只需導航到事件的URL並實現您自己的BrowserNavigationCallback來處理導航到該特定的URL。

這是從廚房水槽演示通知代碼setBrowserNavigationCallback塊:

final WebBrowser wb = new WebBrowser(); 
    if(wb.getInternal() instanceof BrowserComponent) { 
     Button btn = new Button("Add"); 
     final TextArea content = new TextArea(); 
     Container north = new Container(new BorderLayout()); 
     north.addComponent(BorderLayout.CENTER, content); 
     north.addComponent(BorderLayout.EAST, btn); 
     cnt.addComponent(BorderLayout.NORTH, north); 
     content.setHint("Add to web document"); 
     btn.addActionListener(new ActionListener() { 
      public void actionPerformed(ActionEvent evt) { 
       ((BrowserComponent)wb.getInternal()).execute("fnc('" + content.getText() + "');"); 
      } 
     }); 
     ((BrowserComponent)wb.getInternal()).setBrowserNavigationCallback(new BrowserNavigationCallback() { 
      public boolean shouldNavigate(String url) { 
       if(url.startsWith("http://sayhello")) { 
        // warning!!! This is not on the EDT and this method MUST return immediately! 
        Display.getInstance().callSerially(new Runnable() { 
         public void run() { 
          ((BrowserComponent)wb.getInternal()).execute("fnc('this was written by Java code!')"); 
         } 
        }); 
        return false; 
       } 
       return true; 
      } 
     }); 
    }