Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While creating a rich text editor for an iOS application i faced the same problem. Every time i've inserted a <code>&lt;blockquote&gt;</code> tag in my text field and pressed <kbd>Enter</kbd>, it was impossible to get rid off the block-quote. </p> <p>After researching a bit, i've found a working solution.</p> <p><strong>Finding inner HTML tags:</strong></p> <pre><code>function whichTag(tagName){ var sel, containerNode; var tagFound = false; tagName = tagName.toUpperCase(); if (window.getSelection) { sel = window.getSelection(); if (sel.rangeCount &gt; 0) { containerNode = sel.getRangeAt(0).commonAncestorContainer; } }else if( (sel = document.selection) &amp;&amp; sel.type != "Control" ) { containerNode = sel.createRange().parentElement(); } while (containerNode) { if (containerNode.nodeType == 1 &amp;&amp; containerNode.tagName == tagName) { tagFound = true; containerNode = null; }else{ containerNode = containerNode.parentNode; } } return tagFound; } </code></pre> <p><strong>Checking for occurrences of the block-quote tag:</strong></p> <pre><code>function checkBlockquote(){ var input = document.getElementById('text_field_id'); input.onkeydown = function() { var key = event.keyCode || event.charCode; if( key == 13){ if (whichTag("blockquote")){ document.execCommand('InsertParagraph'); document.execCommand('Outdent'); } } }; } </code></pre> <p><strong>Triggering the key down events:</strong></p> <pre><code>&lt;body onLoad="checkBlockquote();"&gt; &lt;!-- stuff... --&gt; &lt;/body&gt; </code></pre> <p>I believe the code above can be adjusted to fit your needs easily. If you need further help, feel free to ask.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload