P
pvsundarram
hey,
i am trying to cancel the keydown event for certain keycodes( for eg:-
enter key ).But the cancelling of this event is not happening in
firefox. Is there any way to cancel the event in the iframe.
CODE
=====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US"
xml:lang="en_US">
<HEAD>
<SCRIPT>
var isIE = document.all;
function chgSpan() {
var newState;
var currentState;
var oSpan = GetObject( "oSpan" );
var oBtn = GetObject( "oBtn" );
InitEventListener();
currentState = (isIE)? oSpan.isContentEditable :
(oSpan.contentDocument.designMode == "on") ;
newState = !currentState;
if(isIE)
oSpan.contentEditable = newState;
else
oSpan.contentDocument.designMode = (newState)? "on" : "off";
newState==false ? oBtn.value="Enable Editing" :
oBtn.value="Disable Editing";
}
function onEnterEvent(e)
{
if(!e)
e = window.event;
var key = (isIE)? e.keyCode : e.which;
alert("onkeydown");
if(key == 13)
{
alert("enter");
return false;
}
}
function InitEventListener()
{
if(isIE)
{
window.document.body.attachEvent("onkeydown",onEnterEvent);
}
else
{
document.getElementById("oSpan").contentWindow.addEventListener("keydown",
onEnterEvent, false);
}
}
function a(ev){
var e = (ev!=undefined)?ev :event;
alert(e);
}
function Init()
{
var EditorBox = (isIE)?
document.createElement("div"):document.createElement("iframe");
EditorBox.id = "oSpan";
EditorBox.name = "oSpan";
document.body.appendChild(EditorBox);
}
function GetObject(idString)
{
return document.getElementById(idString);
}
</SCRIPT>
</HEAD>
<BODY onload="Init();">
<P>Click the button to enable or disable SPAN content editing.</P>
<P>
<input type="button" id="oBtn" value="Enable Editing"
onclick="chgSpan();"/>
</P>
<P></P>
</BODY>
</html>
Thanks in advance....
i am trying to cancel the keydown event for certain keycodes( for eg:-
enter key ).But the cancelling of this event is not happening in
firefox. Is there any way to cancel the event in the iframe.
CODE
=====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US"
xml:lang="en_US">
<HEAD>
<SCRIPT>
var isIE = document.all;
function chgSpan() {
var newState;
var currentState;
var oSpan = GetObject( "oSpan" );
var oBtn = GetObject( "oBtn" );
InitEventListener();
currentState = (isIE)? oSpan.isContentEditable :
(oSpan.contentDocument.designMode == "on") ;
newState = !currentState;
if(isIE)
oSpan.contentEditable = newState;
else
oSpan.contentDocument.designMode = (newState)? "on" : "off";
newState==false ? oBtn.value="Enable Editing" :
oBtn.value="Disable Editing";
}
function onEnterEvent(e)
{
if(!e)
e = window.event;
var key = (isIE)? e.keyCode : e.which;
alert("onkeydown");
if(key == 13)
{
alert("enter");
return false;
}
}
function InitEventListener()
{
if(isIE)
{
window.document.body.attachEvent("onkeydown",onEnterEvent);
}
else
{
document.getElementById("oSpan").contentWindow.addEventListener("keydown",
onEnterEvent, false);
}
}
function a(ev){
var e = (ev!=undefined)?ev :event;
alert(e);
}
function Init()
{
var EditorBox = (isIE)?
document.createElement("div"):document.createElement("iframe");
EditorBox.id = "oSpan";
EditorBox.name = "oSpan";
document.body.appendChild(EditorBox);
}
function GetObject(idString)
{
return document.getElementById(idString);
}
</SCRIPT>
</HEAD>
<BODY onload="Init();">
<P>Click the button to enable or disable SPAN content editing.</P>
<P>
<input type="button" id="oBtn" value="Enable Editing"
onclick="chgSpan();"/>
</P>
<P></P>
</BODY>
</html>
Thanks in advance....