Re: handling bubling events in frameset in IE
From: Martin Honnen (mahotrash_at_yahoo.de)
Date: 01/22/05
- Next message: Dave: "Sever sign on"
- Previous message: selperin: "handling bubling events in frameset in IE"
- In reply to: selperin: "handling bubling events in frameset in IE"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 22 Jan 2005 14:31:20 +0100
selperin wrote:
> I am looking the way to handle events which occur in frames from the frameset.
> According to DOM documentation - events should bubble up in the object model.
But the DOM is only about a single document in which events bubble up
the tree (in the W3C DOM there are two phases, first down the tree from
the root to the target then bubbling up back the tree from the target to
the root) while you are looking at frames in a frameset document, the
events do occur inside the documents in the frames but they are
propagated to the frameset.
Only Netscape 4 (low and behold) has the ability using
enableExternalCapture to set up a single handler in the frameset document.
> I setup the code below in the top level frameset(JSP page) to trap
> onkeypress event in the underlying frames
> for testing:
>
> <HTML>
> <HEAD>
> <SCRIPT LANGUAGE="JavaScript">
> if (document.layers) {
> window.captureEvents(Event.KEYPRESS);
> window.onkeypress = function (evt) {
> alert(evt.type + ' with key ' + evt.which);
> }
> }
> function keyHandler (evt) {
> alert(evt.type + ' with key ' + (evt.which || evt.charCode ||
> evt.keyCode));
> }
> function initEventHandling() {
> if (!document.all && !document.layers)
> for (var f = 0; f < frames.length; f++)
> frames[f].document.addEventListener('keypress', keyHandler, true);
> }
> </SCRIPT>
> <SCRIPT LANGUAGE="JScript">
> function initEventHandling () {
> for (var f = 0; f < frames.length; f++)
> frames[f].document.attachEvent('onkeypress', ieFrameChecker);
> }
> function ieFrameChecker () {
> for (var f = 0; f < frames.length; f++) {
> try {
> var event = frames[f].event;
> var type = frames[f].event.type;
> event.frame = frames[f];
> keyHandler(event);
> }
> catch (e) {
> // ignore e as we are just looking for the
> // frame which has a valid event object
> }
> }
> }
>
> function keyHandler (evt) {
> alert(evt.type + ' in frame ' + evt.frame.name + ' with key ' +
> evt.keyCode);
> }
>
> </SCRIPT>
> </HEAD>
> <FRAMESET ONLOAD="initEventHandling()" ROWS="50%, 50%">
> <FRAME NAME="frame0" SRC="whatever.html">
> <FRAME NAME="frame1" SRC="whatelse.html">
> </FRAMESET>
> </HTML>
You are trying to have your script itself then propagate events from the
frame documents to the parent document, that should work I think:
<http://home.arcor.de/martin.honnen/javascript/200501/test2005012201.html>
Keypress events are handled in the frameset here for me with Netscape 4,
IE 6, Netscape 7, and Opera 7, all tested on Windows.
Of course for the browsers besides Netscape 4 the handlers are attached
to the the currently loaded documents in the frames meaning if someone
loads a new page in a frame (e.g. by following a link in that frame) the
handlers are gone. With IE 5.5/6 and with Netscape 7 (or other Mozilla
browsers) you could however make use of
<frame onload
to make sure you set up the event handler every time a new document has
been loaded in that frame.
-- Martin Honnen http://JavaScript.FAQTs.com/
- Next message: Dave: "Sever sign on"
- Previous message: selperin: "handling bubling events in frameset in IE"
- In reply to: selperin: "handling bubling events in frameset in IE"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|