Web Analytics Made Easy -
StatCounter Editor javascript functionallity - CodingForum

Announcement

Collapse
No announcement yet.

Editor javascript functionallity

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Editor javascript functionallity

    Hi All,

    I need to copy a microsoft word document to my javascript editor
    When toggle to view source code it does show a lot of extra source code that i do not need such as <span tag, font family.
    The only code I like to keep is the <p , <b , <a href , <i tags.
    How can I remove the span and font family tags from the html code ?

    Let me know if I am not clear please

    Thank you in advance

    Code:
    <script type="text/javascript">
    var brswr;
    var viewMode = 1;
    
    function $(el) {
        return document.getElementById(el);
    }
    
    function initWysiwyg() {
        var editor = $('ifm_test');
    
        if(editor.contentWindow && editor.contentWindow.document) {
            brswr = editor.contentWindow.document;
        } else {
            brswr = editor.contentDocument;
        }
        brswr.designMode = 'On';
    }
    
    function normalCommand(c) {
        brswr.execCommand(c, false, null);
    }
    
    function toggleView() {
      if(viewMode == 1) {
        brswr.body.innerHTML = brswr.body.innerHTML
          .replace(/&([lg]t;)/g,'&amp;$1')
          .replace(/</g,'&lt;').replace(/>/g,'&gt;');
        viewMode = 2;
      } else {
        brswr.body.innerHTML = getTextContent(brswr.body);
        viewMode = 1;
      }
      brswr.body.contentEditable=false;
      brswr.body.contentEditable=true;
      setTimeout("$('ifm_test').focus();if(brswr.body.click)brswr.body.click();",1);
    }
    
    function getTextContent(el){ // by Kravvitz of DynamicSiteSolutions.com
      var text='',i=0,kids; // DOM1+ and IE4
      if(!arguments[1]) text=el.textContent||el.innerText||el.data||
        ((el.nodeName&&(el.nodeName.toLowerCase()!='body'))?el.text:'')||'';
      if((!text || /^\s*$/.test(text)) && (kids=el.childNodes))
        while(el=kids[i++])
          switch(el.nodeType){
            case 1:text=text+getTextContent(el,true);break;
            case 3:text=text+el.nodeValue;break;
          }
      return text;
    }
    
    window.onload = function() {
        initWysiwyg();
    }
    </script>
    <style type="text/css">
    a:hover {
        background: #b6bdd2;
        border-color: #0a246a;
    }
    </style>
    
            <table>
                <tr>
                    <td> <a href="#" onclick="normalCommand('bold');" title="bold">B</a> </td>
                    <td> <a href="#" onclick="normalCommand('italic');" title="italic"><i>I</i></a> </td>
                    <td> <a href="#" onclick="toggleView();" title="toggle html/text">toggle</a> </td>
                </tr>
            </table>
    <iframe id="ifm_test" name="ifm_test"></iframe>

  • #2
    I found this other script for anyone who is looking for the same thing as i did
    Create a New Pen
    codepen-io anon pen hFAdk
    Last edited by mp5163093; Oct 5, 2016, 07:49 PM.

    Comment

    Working...
    X