Superq
Superq

Reputation: 153

Remove external html tags when copying into an iframe text editor

I have made my custom iframe based text editor from scratch. I am looking to implement two features now. Here is the iframe :

 <div id="iframe-container" style="height: 200px; width : 450px ; border:1px solid #1d1d1d;">
                                         <iframe id="wysiwygtextfield" onload = 'return iframevents(); ' frameborder="0" style="height:   100%; width:100%;" scrolling="no" >
                                            <html>
                                               <head>

                                                     </head>
                                                <body>
                                                    <br/>

                                                 </body>
                                              </html>
                                            </iframe>
                                      </div>

At times when copy pasting from the web the text contains styling rules of it's own.When the text is pasted into a regular input box the styling disappears on it's own, however the iframe tends to retain the styling. Is there a way to copy paste into a iframe without the HTML tags?

Upvotes: 0

Views: 472

Answers (1)

Muhammad Umer
Muhammad Umer

Reputation: 2308

You can do this using regex:

var String = Sample.replace(/(<([^>]+)>)/ig,"");

Prevent copying text in web-page

Sample is the text being loaded in iframe

replace is a function that changes the matched text to another, which is nothing "".

then append the modified text.

You may have to do this.

  • onchange event select content of textarea
  • run the replace function
  • done. :D

Upvotes: 1

Related Questions