admin管理员组文章数量:1026968
I have an iFrame with designmode turned on. In the document I have several 'special' elements which can be pasted by the user through menu selections (custom characters/identifiers/descriptions used within the wider application that are fixed). I need to protect these html elements from modification and treat them as a single entity if the user chooses to select or delete them. An example iframe would look like this:
<iframe>
<html dir="ltr">
<head></head>
<body class="editableDoc">
<p>Here is a <span class="special readonly">SPECIAL</span> character</p>
</body>
</html>
</iframe>
Design mode enables editing of the whole body contents which is exactly as I need it.
What would be the best way to protect the 'readonly' span? The best description I can give is that I want the span and its contents to be treated as if it were a single character for all user text operations (i.e. moving the cursor, selecting, deleting). I have tried setting contenteditable="false" on the span element and this does have many of the desired effects, but it works badly in IE8/9 and has other, smaller issues in other browsers. Plus I'm not sure mixing designmode and contenteditable in the same solution is a good idea.
I have an iFrame with designmode turned on. In the document I have several 'special' elements which can be pasted by the user through menu selections (custom characters/identifiers/descriptions used within the wider application that are fixed). I need to protect these html elements from modification and treat them as a single entity if the user chooses to select or delete them. An example iframe would look like this:
<iframe>
<html dir="ltr">
<head></head>
<body class="editableDoc">
<p>Here is a <span class="special readonly">SPECIAL</span> character</p>
</body>
</html>
</iframe>
Design mode enables editing of the whole body contents which is exactly as I need it.
What would be the best way to protect the 'readonly' span? The best description I can give is that I want the span and its contents to be treated as if it were a single character for all user text operations (i.e. moving the cursor, selecting, deleting). I have tried setting contenteditable="false" on the span element and this does have many of the desired effects, but it works badly in IE8/9 and has other, smaller issues in other browsers. Plus I'm not sure mixing designmode and contenteditable in the same solution is a good idea.
Share Improve this question edited May 30, 2012 at 7:18 Jason asked May 28, 2012 at 8:47 JasonJason 2,3312 gold badges24 silver badges24 bronze badges2 Answers
Reset to default 4You can use contentEditable=false
like so:
<body contenteditable>
<p>Here is a <span contenteditable='false'>SPECIAL</span> character</p>
</body>
This works whether it's in an iframe or not. It works in Chrome and Firefox — likely works in recent IEs too, considering that it's not prefixed.
Demo at: http://codepen.io/bfred-it/pen/bGhaC
A similar question here: contenteditable=false inside contenteditable=true block is still editable in IE8
Use the read-only
value of the user-modify
CSS property to protect a span in Firefox and Chrome:
<iframe src="about:blank" srcdoc="<body contenteditable><span style='-webkit-user-modify: read-only; -moz-user-modify: read-only;'>Hi</span></body>">
</iframe>
I have an iFrame with designmode turned on. In the document I have several 'special' elements which can be pasted by the user through menu selections (custom characters/identifiers/descriptions used within the wider application that are fixed). I need to protect these html elements from modification and treat them as a single entity if the user chooses to select or delete them. An example iframe would look like this:
<iframe>
<html dir="ltr">
<head></head>
<body class="editableDoc">
<p>Here is a <span class="special readonly">SPECIAL</span> character</p>
</body>
</html>
</iframe>
Design mode enables editing of the whole body contents which is exactly as I need it.
What would be the best way to protect the 'readonly' span? The best description I can give is that I want the span and its contents to be treated as if it were a single character for all user text operations (i.e. moving the cursor, selecting, deleting). I have tried setting contenteditable="false" on the span element and this does have many of the desired effects, but it works badly in IE8/9 and has other, smaller issues in other browsers. Plus I'm not sure mixing designmode and contenteditable in the same solution is a good idea.
I have an iFrame with designmode turned on. In the document I have several 'special' elements which can be pasted by the user through menu selections (custom characters/identifiers/descriptions used within the wider application that are fixed). I need to protect these html elements from modification and treat them as a single entity if the user chooses to select or delete them. An example iframe would look like this:
<iframe>
<html dir="ltr">
<head></head>
<body class="editableDoc">
<p>Here is a <span class="special readonly">SPECIAL</span> character</p>
</body>
</html>
</iframe>
Design mode enables editing of the whole body contents which is exactly as I need it.
What would be the best way to protect the 'readonly' span? The best description I can give is that I want the span and its contents to be treated as if it were a single character for all user text operations (i.e. moving the cursor, selecting, deleting). I have tried setting contenteditable="false" on the span element and this does have many of the desired effects, but it works badly in IE8/9 and has other, smaller issues in other browsers. Plus I'm not sure mixing designmode and contenteditable in the same solution is a good idea.
Share Improve this question edited May 30, 2012 at 7:18 Jason asked May 28, 2012 at 8:47 JasonJason 2,3312 gold badges24 silver badges24 bronze badges2 Answers
Reset to default 4You can use contentEditable=false
like so:
<body contenteditable>
<p>Here is a <span contenteditable='false'>SPECIAL</span> character</p>
</body>
This works whether it's in an iframe or not. It works in Chrome and Firefox — likely works in recent IEs too, considering that it's not prefixed.
Demo at: http://codepen.io/bfred-it/pen/bGhaC
A similar question here: contenteditable=false inside contenteditable=true block is still editable in IE8
Use the read-only
value of the user-modify
CSS property to protect a span in Firefox and Chrome:
<iframe src="about:blank" srcdoc="<body contenteditable><span style='-webkit-user-modify: read-only; -moz-user-modify: read-only;'>Hi</span></body>">
</iframe>
本文标签: javascriptHow to protect an HTML element within designmodeonStack Overflow
版权声明:本文标题:javascript - How to protect an HTML element within designmode=on - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745650297a2161277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论