V
Vincent van Beveren
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
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