2016-12-18 回答
/* * 以下代码就是拦截弹窗的。 * 先要监听打开新窗口事件,如果有的话就把新窗口嵌入,然后关闭这个新窗口的shell.同时取出url */ browser.addopenwindowlistener(new openwindowlistener(){ public void open(windowevent e){ // embed the new window final shell shell = new shell(display); final browser browser2 = new browser(shell, swt.none); system.out.println("1111关闭的url:"+browser2.geturl()); e.browser = browser2;//将e的事件用我的浏览器打开 system.out.println("222关闭的url:"+browser2.geturl()); e.display.asyncexec(new runnable() { //swt对外观部件的更改必须在swt异步线程中进行哦! public void run() { string url = browser2.geturl(); system.out.println("关闭的url:"+url); browser.seturl(url); shell.close(); }}); }
} );