Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)


Each DOMNode implements DOMEventTarget interface that provides methods for registering DOM events. You can register DOM listener to receive DOM events such as click, mousedown, mouseup, keydown, load, error etc. The following sample demonstrates how to register click event listener for a document HTML element: (每个DOMNode实现DOMEventTarget接口,该接口提供注册DOM事件的方法。您可以注册DOM侦听器以接收DOM事件,例如click,mousedown,mouseup,keydown,load,error等。以下示例演示如何为文档HTML元素注册click事件侦听器:)

DOMElement element = document.getDocumentElement();
element.addEventListener(DOMEventType.OnClick, new DOMEventListener() {
    public void handleEvent(DOMEvent event) {
        // user clicked document element
    }
}, false);

You can register DOM event listener only for the document of the loaded web page. After reloading the web page, all the registered DOM event listeners will not work anymore, so you need to register the required DOM event listeners again.(您只能为已加载网页的文档注册DOM事件侦听器。重新加载网页后,所有已注册的DOM事件监听器将不再起作用,因此您需要再次注册所需的DOM事件监听器。)


Custom DOM Event Types(自定义DOM事件类型)

JxBrowser allows you to listen to the custom DOM Event types as well. The following code demonstrates how to listen to the MyEvent DOM Events:(JxBrowser允许您也收听自定义DOM事件类型。下面的代码演示了如何侦听MyEvent DOM事件:)

DOMElement element = document.getDocumentElement();
element.addEventListener(new DOMEventType("MyEvent"), new DOMEventListener() {
    public void handleEvent(DOMEvent event) {
    }
}, false);