Netscape Navigator requires the captureEvents() method to capture events outside of its intended target (in the window, layer, or document object). For example, the following code segment captures all mouseup events in the document: document.captureEvents(Event.MOUSEUP);
document.onmouseup = functionName;Since Internet Explorer's event model is based on event bubbling, an event is first directed to its intended target (the element that initiated the event). Therefore, the captureEvents() method is not featured in Internet Explorer. It simply isn't required. As a scripter, you must make sure it is not executed under Internet Explorer. The best way to do this is by object detection. The following statements define a cross-browser event capturing routine:
if (window.Event) // Navigator 4.0x
document.captureEvents(Event.MOUSEUP);
document.onmouseup = functionName;On Internet Explorer 4.0x and older browsers (Navigator and Internet Explorer), only the second statement is executed. Therefore this script is also backward compatible. In other words, it does not generate an error on older browsers. It obviously doesn't work with such browsers, because they do not support the onmouseup event handler with the document object. Note that under some circumstances, the onclick event handler doesn't work properly with the document object on Navigator 4.0x and up, so we'll use the onmouseup event handler instead. The following script is a complete example that demonstrates the object detection routine:
<SCRIPT LANGUAGE="JavaScript">
<!--function processClicks() {
alert("You released the mouse button.");
}if (window.Event) // Navigator 4.0x and up
document.captureEvents(Event.MOUSEUP);
document.onmouseup = processClicks;// -->
</SCRIPT>
document.onmouseup = functionName;Since Internet Explorer's event model is based on event bubbling, an event is first directed to its intended target (the element that initiated the event). Therefore, the captureEvents() method is not featured in Internet Explorer. It simply isn't required. As a scripter, you must make sure it is not executed under Internet Explorer. The best way to do this is by object detection. The following statements define a cross-browser event capturing routine:
if (window.Event) // Navigator 4.0x
document.captureEvents(Event.MOUSEUP);
document.onmouseup = functionName;On Internet Explorer 4.0x and older browsers (Navigator and Internet Explorer), only the second statement is executed. Therefore this script is also backward compatible. In other words, it does not generate an error on older browsers. It obviously doesn't work with such browsers, because they do not support the onmouseup event handler with the document object. Note that under some circumstances, the onclick event handler doesn't work properly with the document object on Navigator 4.0x and up, so we'll use the onmouseup event handler instead. The following script is a complete example that demonstrates the object detection routine:
<SCRIPT LANGUAGE="JavaScript">
<!--function processClicks() {
alert("You released the mouse button.");
}if (window.Event) // Navigator 4.0x and up
document.captureEvents(Event.MOUSEUP);
document.onmouseup = processClicks;// -->
</SCRIPT>
解决方案 »
- 关于js替换选中文字!!要兼容...求高手帮忙啊~~
- 高手啊 来帮帮我啊 谁能告诉我 onload 和onunload 刷新不触发的办法
- menu4.js的menuButton能不能加url
- 动态创建一个chekbox 的onclick却在创建是自动执行.????
- 关于网页中取得某个按钮的坐标
- 用js给input输入框赋值,并不触发input输入框的onchange 事件?
- 请问如何让web页面每隔几秒显示数据库中的数据
- 请问select下拉框中onchange事件的this问题?
- zhangchunlei老兄进来拿分,见者有份
- jquery dialog open时总是会重新刷新网页
- 请问这样写对?mediapath=document.form1.radioname.value;这是一个单选按钮值,但是告诉我错误
- 不能实时显示秒数
Netscape Navigator 4.0x provides a new way to handle events. In older browsers, the only way to react to an event was to specify an event handler (in HTML or JavaScript) for the desired element. That is, the event was processed by its target. There was no way to catch an event at a level different from the event's target. In Navigator 4.0x, you can capture an event in the window, layer, or document object before the event ever reaches its intended target. For example, you may want the document object to handle all mouseover (remember, mouseover is an event, while onmouseover is an event handler) events, no matter where they occur in the document.JavaScript's event capturing model now lets you define functions that capture and handle events before they reach their intended target. By default, all events are captured by their intended target. For example, when the user clicks a button, the click event handler is normally captured by the button's onclick event handler. You must explicitly enable this capability for the window, layer, and document objects. The capability can also be turned off at any time. To accomplish these tasks, use the following methods:
window.captureEvents()
layer.captureEvents()
document.captureEvents()window.releaseEvents()
layer.releaseEvents()
document.releaseEvents()For example, if you want a document to capture events at all times while the document is loaded, you would execute the window.captureEvents() when the page loads. The captureEvents() and releaseEvents() methods obviously require an argument specifying the type of event to capture. Here are a few examples of how that's done:
window.captureEvents(Event.CLICK);
window.releaseEvents(Event.CLICK);window.captureEvents(Event.MOUSEDOWN);
window.releaseEvents(Event.MOUSEDOWN);window.captureEvents(Event.MOUSEUP);
window.releaseEvents(Event.MOUSEUP);window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
window.releaseEvents(Event.MOUSEDOWN | Event.MOUSEUP);Notice that the event (not event handler) is spelled in all uppercase. For example, Event.CLICK is the click event value, and Event.KEYPRESS is the keypress event value. Don't worry about the constant Event object and the new events, because we'll discuss them later in the column.You probably noticed from the preceding example that you can specify multiple event values at a time. Simply separate the event values with the pipe character (|). The following script segments are equivalent:
// first segment
window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP);// second segment
window.captureEvents(Event.CLICK);
window.captureEvents(Event.MOUSEDOWN);
window.captureEvents(Event.MOUSEUP);You can capture, say, three types of events at the window level, and then release only one of them. The other two would continue to be captured.