How to get only html code without <!--StartFragment--> on paste in contenteditable div..?

自作多情 提交于 2019-12-24 07:26:20

问题


I used contenteditable div to paste and replace all html tags with <br> tag. But the pasted html start with <html><body><!--StartFragment--> and end with <!--EndFragment--></body></html>.

When i try to replace pasted html with <br> tag, it inserts three <br> tags at start position. So the pasted content start and end with three line breaks unnecessarily.

How to remove those unwanted tags on paste..?

Javascript code used to get pasted html content:

$(document).on('paste','#div-id',function(e){ 
  e.preventDefault();
  var pastedData = e.originalEvent.clipboardData.getData('text/html');
});

Note: Used regex to replace all tags with break tag(except <img> and <br> tag)

var replacedData = pastedData.replace(/\<(?!img|br).*?\>/g,"<br>");

来源:https://stackoverflow.com/questions/43649792/how-to-get-only-html-code-without-startfragment-on-paste-in-contenteditab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!