On InternetExplorer, a contentEditable DIV creates a new paragraph (<p></p>
) each time you press Enter whereas Firefox creates a <br/>
tag.
Is it possible to force IE to insert a <br/>
instead of a new paragraph ?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
-
Why does the box-shadow property not apply to a
Changing the
line-height
of the<p>
inside the editable<div>
works:Here's a solution (uses jQuery). After you click on the 'Change to BR' button, the
<br>
tag will be inserted instead of the<p></p>
tag.Html:
Javascript:
These links helped. Working example here.
Yes it is possible to avoid the insertion of paragraphs by stopping the keydown event first (
window.event.stopPropagation();
) and then inserting the string by using insert HTML command.However, IE depends on this divs for setting styles etc. and you will get into trouble using <br>s.
I suggest you using a project like TinyMCE or other editors and search for an editor which behaves the way you would like, since they have all kinds of workarounds for different browser issues. Perhaps you can find an editor which uses <br>s...
If you can use it, FCKEditor has a setting for this
You can always learn to use SHIFT + ENTER for single line returns and ENTER for paragraph returns. IE behaves like MS Word in this respect.