iframe design=on 时,oncontextmeun不能触发之问题!
今天写一个类似编辑器的玩意,需要在iframe中实现自定义右键彩单。
编辑器代码:edit.htm
<html>
<head></head>
<script language="javascript">
</script>
<body onload="edit.document.designMode='on'" >
<table border="1" width="100%" id=edit >
<tr>
<td width="100%">
<IFRAME id=edit marginWidth=0 marginHeight=0 src="test.htm" frameBorder=1 width="100%" height="100%" src="bb.htm"></IFRAME>
</td>
</tr>
</table>
</body>
<html>
<head></head>
<script language="javascript">
</script>
<body onload="edit.document.designMode='on'" >
<table border="1" width="100%" id=edit >
<tr>
<td width="100%">
<IFRAME id=edit marginWidth=0 marginHeight=0 src="test.htm" frameBorder=1 width="100%" height="100%" src="bb.htm"></IFRAME>
</td>
</tr>
</table>
</body>
<html>
<html>
<body oncontextmenu="alert('xxxx')" >
aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbb<br>
<input type=text value="xxxx" >
<table width=1200 border=1>
<tr><td>xxxx</td></tr>
<tr><td>aaaa</td></tr>
<tr><td>mmmmm</td></tr>
</table>
</body>
</html>
<body oncontextmenu="alert('xxxx')" >
aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbb<br>
<input type=text value="xxxx" >
<table width=1200 border=1>
<tr><td>xxxx</td></tr>
<tr><td>aaaa</td></tr>
<tr><td>mmmmm</td></tr>
</table>
</body>
</html>
后来发现edit.htm这样写就行了:
<script language="javascript">
function showContextMenu()
{
//child.focus();
alert("Show it!");
return false;
}
edit.document.designMode="on";
edit.document.focus();
edit.document.contentEditable = true;
edit.document.oncontextmenu = showContextMenu;
//edit.document.selection.createRange().setEndPoint("StartToStart",1)
</script>
function showContextMenu()
{
//child.focus();
alert("Show it!");
return false;
}
edit.document.designMode="on";
edit.document.focus();
edit.document.contentEditable = true;
edit.document.oncontextmenu = showContextMenu;
//edit.document.selection.createRange().setEndPoint("StartToStart",1)
</script>
问题其实不大,原因不明。。以后在研究!