Untitled

 avatar
unknown
plain_text
5 months ago
1.7 kB
6
Indexable
<iframe id="contentFrame" width="1024" height="800"></iframe>

<script>
function convertHTMLEntities(input, toEscape) {
    if (toEscape) {
        return input
            .replace(/>/g, '&gt;')
            .replace(/</g, '&lt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&apos;')
            .replace(/&/g, '&amp;');
    } else {
        return input
            .replace(/&gt;/g, '>')
            .replace(/&lt;/g, '<')
            .replace(/&quot;/g, '"')
            .replace(/&apos;/g, "'")
            .replace(/&amp;/g, '&');
    }
}

// Assuming noteEditable is the boolean variable
var noteEditable = true; // or false, depending on your logic
var noteBody = '<p>This is the content of the note</p>'; // Placeholder for the note content

var contentFrame = document.getElementById("contentFrame");

if (noteEditable) {
    // Load the KendoFrame if noteEditable is true
    contentFrame.src = "./javascript/kendo/index.html";
    contentFrame.onload = function () {
        var outerIframe = contentFrame.contentDocument.querySelector('.k-editor-content');
        var p = outerIframe.getElementsByTagName('p')[0];
        if (p) {
            p.innerHTML = convertHTMLEntities(noteBody, false);
        }
    };
} else {
    // Load a basic HTML page with the noteBody content if noteEditable is false
    var htmlContent = `
        <html>
        <head><title>Note</title></head>
        <body>${convertHTMLEntities(noteBody, false)}</body>
        </html>
    `;
    var blob = new Blob([htmlContent], { type: 'text/html' });
    var url = URL.createObjectURL(blob);
    contentFrame.src = url;
}
</script>
Editor is loading...
Leave a Comment