Как вывести html-код текстом
При таком выводе в фрейме рендерится полностью страница, как сделать что бы был только текст.
function displayFileContent(){
fetch(filePath)
.then(response => response.text())
.then(data => {
var iframe = document.getElementById('contentContainer');
iframe.srcdoc = data;
});
}
Ответы (1 шт):
Автор решения: AfteRDay
→ Ссылка
function escapeHTML(str) {
var map = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
return str.replace(/[&<>"']/g, function(m) { return map[m]; });
}
function displayFileContent(){
fetch(filePath)
.then(response => response.text())
.then(data => {
var iframe = document.getElementById('contentContainer');
iframe.srcdoc = escapeHTML(data);
});
}