Dealing with line Breaks on contentEditable DIV

后端 未结 7 1772
粉色の甜心
粉色の甜心 2020-11-27 12:41

I have a problem with contenteditable line breaks on SAFARI/CHROME. When I press \"return\" on a contentEditable

, instead of creating a
7条回答
  •  执笔经年
    2020-11-27 13:09

    Listening to keystrokes seems like a lot of work. Would something as simple as this be feasible:

    var html = $('.content').html().replace(/
    /gi,'
    ').replace(/<\/div>/gi,'');

    JSFiddle demo here.

    Also, it looks like sanitize.js allows a custom configuration. Have you tried adding div as an allowed element?

    Allowing HTML/CSS is dangerous, so ensure you are being extra cautious.

    EDIT: Removed server side comments. Sanitising occurs at time of usage- if the client wants to bypass this locally it can be done so at their own risk. Thanks Vincent McNabb for pointing this out.

提交回复
热议问题