How to force breaking of non breakable strings?

后端 未结 9 1175
-上瘾入骨i
-上瘾入骨i 2021-02-04 18:52

I have an HTML page that I generate from the data contained in a database. The database sometimes contains long strings that the browser can\'t break because the strings don\'t

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 19:34

    I'm answering my own question here...

    Based on your answers, I came up with this solution (thanks to @CMS in this question for his help).

    This script breaks any word that is more than 30 characters long by inserting a space at the 31st position.

    Here is the fixed version: link

    I have one problem left, I'd rather insert a ­ then a space. But the assigning node.nodeValue or node.textContent causes the insertion of the text ­ not the tag.

    
    

    I'll wait a few days before I accept this answer in case someone comes up with a simpler solution.

    Thanks

提交回复
热议问题