473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

captureEvents in Netscape 7

Hey everyone,

I have trouble capturing events in Netscape 7.1.

I am building a WYSIWYG editor thingy which should both work in IE and
NS 7. For this I use designMode='on'. However, it seems like as soon as
I do that, it stops capturing events from that element.

//
// EditGUI is a simple WYSIWYG editor for chat
///////////////////////////////////////////////////////////////

function EditGUI() {
this.document = null;
this.window = null;
this.body = null;
this.content = null;

this.writeHere = function(width, height, className)
{
iframe = writeIFrame(width,height, className);
this.window = iframe.contentWindow;
this.document = this.window.document;
this.body = this.document.body;
// make it editable
if ("contentEditable" in this.body) {
// IE
this.content = this.document.createElement('P');
this.content.contentEditable = true;
this.body.appendChild(this.content);
} else if ("designMode" in this.document) {
// NS 7
this.content = this.document.body;
this.document.designMode = "on";
}

// install callback reference
this.document.backRef = this;

if ("captureEvents" in this.document) {
this.document.captureEvents(Event.KEYPRESS);
}

this.document.onkeypress = function(event) {
event = (event!=null?event:window.event);
this.backRef.key(event);
}
}

this.key = function(event) {
alert('yes, you pressed a key!');
}
}

//
// appends an iframe to the current part of the document and
// returns its reference.
/////////////////////////////////////////////////////////////////

function writeIFrame(width, height, className) {
iframe = document.createElement('IFRAME');
if (className) iframe.className = className;
iframe.style.width=width;
iframe.style.height=height;
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
doc.open();
doc.close();
return iframe;
}

Now this works perfectly in Internet Explorer. But whatever I try, I
can't get Netscape to display 'yes, you pressed a key'. There are no
errors either. It does work if I turn designMode off. Anyone have any idea?

Thanks in advance,
Vincent

Jul 23 '05 #1
6 2183


Vincent van Beveren wrote:

[captureEvents]
I have trouble capturing events in Netscape 7.1.


The method captureEvents is part of the Netscape 4 event model/api, it
also somehow made it into Mozilla and Netscape 6/7 but shouldn't be used
there as they implement the W3C DOM Level 2 event model/api which has
its own way to capture events i.e.
document.addEventListener(
'keypress',
function (evt) {
alert(evt.type);
},
true
);
Looking at your code I don't think you really want to use event
capturing in the sense of the DOM Level 2 event model but simply want to
handle the keypress event at the document node so you can probably use
false instead of true above.
I haven't tested whether handling key events with Netscape 7 works
properly in an iframe with designMode editing enabled but if it doesn't
that is most certainly not a problem cured with captureEvents in any
way. You might want to search bugzilla.mozilla.org whether there are any
bugs filed for key event handling in editable iframes maybe they have
been fixed after Netscape 7.1 (which is based on Mozilla 1.4).
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Thanks for your quick reply.
The method captureEvents is part of the Netscape 4 event model/api, it
also somehow made it into Mozilla and Netscape 6/7 but shouldn't be used
there as they implement the W3C DOM Level 2 event model/api which has
its own way to capture events i.e.
The captureEvents was a last resort. I also included it so people
wouldn't reply with 'did you try to use captureEvents'.

I tried your code, but then it doesn't work at all, not even in IE.

this.document.addEventListener('onkeypress',
function(event) {
event = (event!=null?event:window.event);
this.backRef.key(event);
}, true); // also tried false
Neither does it give any error... hmm...

You might want to search bugzilla.mozilla.org whether there are any
bugs filed for key event handling in editable iframes maybe they have
been fixed after Netscape 7.1 (which is based on Mozilla 1.4).


That could be. But even if it wouldn't solve it. It needs to run for an
as broad audience as posssible.

any other ideas?

Vincent

Jul 23 '05 #3


Vincent van Beveren wrote:

> The method captureEvents is part of the Netscape 4 event model/api, it
> also somehow made it into Mozilla and Netscape 6/7 but shouldn't be used
> there as they implement the W3C DOM Level 2 event model/api which has
> its own way to capture events i.e.


The captureEvents was a last resort. I also included it so people
wouldn't reply with 'did you try to use captureEvents'.

I tried your code, but then it doesn't work at all, not even in IE.


Well, I have not suggested to use addEventListener for IE.
addEventListener is part of the W3C DOM Level 2 events model and IE
doesn't implement that.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #4


Vincent van Beveren wrote:

I tried your code, but then it doesn't work at all, not even in IE.

this.document.addEventListener('onkeypress',
function(event) {
event = (event!=null?event:window.event);
this.backRef.key(event);
}, true); // also tried false


I have made a short example at
http://home.arcor.de/martin.honnen/j...t20040528.html
and here with Netscape 7.1, some Mozilla 1.7a and Firefox 0.8 all on
Windows the keypress event listener is called when I type in the iframe.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #5
Vincent van Beveren wrote:

Please provide proper attribution. A line including the
author of the quoted material is sufficient (see above).
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvv
The method captureEvents is part of the Netscape 4 event model/api, it
also somehow made it into Mozilla and Netscape 6/7 but shouldn't be used
there as they implement the W3C DOM Level 2 event model/api which has
its own way to capture events i.e.
The captureEvents was a last resort. I also included it so people
wouldn't reply with 'did you try to use captureEvents'.

I tried your code, but then it doesn't work at all, not even in IE.

this.document.addEventListener('onkeypress',


The event identifier is "keypress", its intrinsic handler is
"onkeypress". addEventListener() expects the identifier, not
the handler.
function(event) {
event = (event!=null?event:window.event);
this.backRef.key(event);
Looks like fantasy syntax.
}, true); // also tried false
Neither does it give any error... hmm...


1. Why should it? There could be an "onkeypress" event in a DOM.
2. Maybe it does. Watch Mozilla's JavaScript console.
PointedEars
Jul 23 '05 #6
Thanks everyone for replying!

Vincent van Beveren wrote:
this.document.addEventListener('onkeypress',
function(event) {
event = (event!=null?event:window.event);
this.backRef.key(event);
}, true); // also tried false


The problem was that it should have been 'keypress' and not
'onkeypress'. Now it works perfectly, though I had to make
an exception for IE. I wrote the following code:

this.document.backRef = this;
this.document.onkeyup = function(event)
{
event = (event?event:this.parentWindow.event);
this.backRef.keyUp(new WrappedEvent(event));
};

if (this.document.addEventListener) {
this.document.addEventListener('keyup', this.document.onkeyup,
false);
}

I choose key up later, cause it suited the cause better.
The wrappedEvent object is a generic event object so that I
don't need to worry about incompatibility issues. (blah)

I wish that IE was somewhat more DOM complient.

Thanks,
Vincent

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sims | last post by:
Hi, if i use... // php $info = getenv("HTTP_USER_AGENT"); // I noticed that Mozzila and Netscape <6(?) both use the same Agent. // so i was thinking of if...
6
by: Dave | last post by:
Hi, With this code, I thought that any 'click' with the mouse would be captured on the window level and nothing would happen, but a click on the button triggers nevertheless the function hit()....
9
by: rez | last post by:
I find it rather frustrating that Netscape 4.x is "no longer supported:" http://help.netscape.com/products/client/communicator/reflib.html Same seems true with IE. How am I ever supposed to...
2
by: Phil | last post by:
Hello all ! I need help with this script : It's a tooltip appearing onMouseOver on a link. It works fine in IE, Opera but not Netscape 7 and Mozilla 1.5. The tooltip sticks on the top left...
2
by: ALuPin | last post by:
Hi, when I try to see the effect of the following script I do not see anything when using Netscape Navigator whereas InternetExplorer ist ok. In Netscape Javascript is activated. What could...
2
by: Obi Wan Shinobi | last post by:
I can't seem to prevent the refresh associated with F5 in Netscape. I can capture the key but returning false does not prevent the refresh. The code is as follows: function keyDown(e) { if...
2
by: harry | last post by:
Hi I am trying to add an event handler to the window so that If the user clicks the close window button, it creates a popup to tell the user it should use the log out button before closing window....
10
by: News | last post by:
I have a page up trying to learn how to ID a browser and other info. http://wyght.com/warren/testPos.html here is the code <script type = "text/javascript"> var space = ", "; var name...
4
by: Nathan Sokalski | last post by:
I was testing out a page of mine that displays the information from Page.Request.Browser. It works exactly as I expected in Internet Explorer and Netscape 4.75 (I didn't expect much in Netscape...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.