<html><head></head><body> <div contentEditable="true"><b>C</b>ontent<u>!!!</u></div> </body></html>
working example<html> <head> <script language = "javascript"> <! - / * Turning the iframe into the editing area, see below (the following JS code) * / // -> </ script> </ head> <body> <iframe id = "frm"> </ iframe> </ body> </ html>
var NewTextArea = {
frame: {},
document: {},
window: {},
init: function (frame) {
NewTextArea.frame = frames [frame]? Frames [frame]: document .getElementById (frame); // IE, Opera - frames.document, others - ById.document
if (! NewTextArea.frame) {
alert ( "Error ID" );
return -1;
}
// 1) get pointer
NewTextArea. document = NewTextArea.frame.contentDocument || NewTextArea.frame. document ;
if (! NewTextArea. document ) {
alert ( "Error iframe" );
return -2;
}
NewTextArea.window = NewTextArea.frame.contentWindow || NewTextArea.frame.window;
if (! NewTextArea.window) {
alert ( "window" );
return -2;
}
// 2) Design an iframe HTML document
var HTML = "<html> <head> </ head> <body>"; HTML + = "<u> Document </ u> <b> HTML </ b>"; HTML + = "</ body> </ html>"
NewTextArea. document .open ();
NewTextArea. document .write (HTML);
NewTextArea. document .close ();
// 3) Set the designMode
if (NewTextArea. document .designMode) {
NewTextArea. document .designMode = 'on' ;
} else {
alert ( "Error designMode" );
return -3;
}
}
}
* This source code was highlighted with Source Code Highlighter .
working example... <body onload = "NewTextArea.init ('frm')"> <iframe id = "frm"> </ iframe> </ body>
working example... <body onload = "NewTextArea.init ('frm')"> <iframe id = "frm"> </ iframe> <input type = "button" value = "B" onclick = "NewTextArea.window.focus (); NewTextArea.document.execCommand ('bold', null, '')" /> <input type = "button" value = "I" onclick = "NewTextArea.window.focus (); NewTextArea.document.execCommand ('italic', null, '')" /> <input type = "button" value = "U" onclick = "NewTextArea.window.focus (); NewTextArea.document.execCommand ('underline', null, '')" /> </ body>
... var HTML = "<html> <head> <style>"; HTML + = "html, body {margin: 0px; padding: 0px; background: black; color: white; font-size: 20px}"; HTML + = "p, div, span {margin: 0px; padding: 0px}"; HTML + = "</ style> </ head> <body>"; HTML + = "<u> Document </ u> <b> HTML </ b>"; HTML + = "</ body> </ html>"; ...
You can also do the loading of the text field style from the .css file by inserting the appropriate <link ...> tag instead of the <style>.
Source: https://habr.com/ru/post/43317/
All Articles