4
4
4eloBek2015-08-01 22:45:11
JavaScript
4eloBek, 2015-08-01 22:45:11

Replacing html text (WYSIWYG)?

I'm trying to concoct an html editor for a static site (there are unique tags). Can you please tell me how to replace the text I entered?
Inserted with paragraphs((
3bc1855a13524e63a9c62f1c1fa4b6fc.png
____

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
          <link type="text/css" rel="stylesheet" href="demo.css" />
  </head>
  <body>
<div class="main">
  <center><h1>HTML-редактор</h1></center>
  <br>
<a href="#" onclick="f1('h1')">h1</a> 
<a href="#" onclick="f1('h2')">h2</a> 
<a href="#" onclick="f1('h3')">h3</a> 
<a href="#" onclick="f1('h4')">h4</a> 
<a href="#" onclick="f1('h5')">h5</a> 
<a href="#" onclick="f1('h6')">h6</a> 

<div id="content" contenteditable="true"></div>
</div>

  <script type="text/javascript">
  var div = document.createElement('div');
    function f1(val){
      if (document.getSelection()['type'] == 'Range'){
        var txt = document.getElementById("content").innerHTML;
        var n1 = document.getSelection().anchorOffset;
        var n2 = document.getSelection().focusOffset;
        div.innerHTML = txt.substring(0, n1) + "<" + val + ">" + window.getSelection().toString() + "</" + val + ">" + txt.substring(n2, txt.length);
        content.appendChild(div);	
      }
    }
  </script>
  </body>
</html>

PS I use only chrome...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question