execcommand

execcommand on empty selection

时光怂恿深爱的人放手 提交于 2019-12-22 09:21:39
问题 I'm working on a specialized Text/HTML Editor with Javascript and JQuery in a contenteditable div. I implemented the different text styles (bold, italic,...) with execcommand. This seems to work only if the selected text is not empty. What is the best way to solve this problem? Here an example of what I want to do with Text being the text in the editor, HTML being the corresponding html code and | being the cursor Position: Text: Hello| World HTML: <b>Hello| World</b> By pressing a "bold"

Is there a way to keep execCommand(“insertHTML”) from removing attributes in chrome?

血红的双手。 提交于 2019-12-18 11:32:53
问题 Context is Chrome 37.0.2062.120 m. I'm using execCommand to insert html into an editable div. My execCommand call looks like this: function insertHTML(){ document.execCommand('insertHTML', false, '<span id="myId">hi</span>'); } When the editable div looks like this: <div contenteditable="true"> some [insertion point] content </div> and I use execCommand to insert html into a contenteditable div, all of the attributes of the HTML are inserted as expected and I end up with this: <div

Contenteditable div vs. iframe in making a rich-text/wysiwyg editor

女生的网名这么多〃 提交于 2019-12-18 10:27:54
问题 i'm trying to weigh the pros and cons of using a <div> vs. <iframe> in making my own rich text/wysiwyg editor. In doing so, why can't I just use a contenteditable <div> and why do so many people prefer the <iframe> ? Background discussion: A common way to go about making a wysiwyg editor as I understand is to make a div or iframe contenteditable and to then to do execCommand on the document containing the div or the iframe body to make its text bold or whatever. Here's the HTML: <html><!-

How to add class or id or CSS style in execCommand formatBlock 'p' tag?

a 夏天 提交于 2019-12-17 19:09:36
问题 I want to use execCommand('formatblock') to select a line with the <p> tag or <span> with a specific class or id or any CSS style in my contentEditable <div> (own rich text editor). document.execCommand('formatblock', false, 'p'>; How can I add a class or id or CSS in this code? 回答1: If you want to add id or class for CSS in content editable div, then you will use below code--- <script> function CssFnctn() { document.execCommand('formatblock', false, 'p') var listId = window.getSelection()

execCommand insertHTML breaks stored window.getSelection()

瘦欲@ 提交于 2019-12-17 10:07:37
问题 When using methods of selecting text and restoring selected text in a page, I have found that running execCommand('insertHTML... inbetween causes the stored selection to break. This is a sample of how the text is selected and restored. // Get Selection var sel = window.getSelection().getRangeAt(0); // Clear Selections window.getSelection().removeAllRanges(); // Restore Selection window.getSelection().addRange(sel) This works fine, however once you run execCommand('insertHTML.. the selections

make document.execCommand('insertText', false, 'message') work with draftjs?

◇◆丶佛笑我妖孽 提交于 2019-12-12 19:40:12
问题 I'm working on an application which needs to insert text into a contenteditable="true" div (a Draftjs based textfield to be precise). Now I am aware that Draft.js uses react and that it should be used that way, but in this case, the application already exists and this is a third party electron app that works with it. I'm working on in-line notification replying on macOS, so I need that reply text to be pasted inside the draftJS field, however, when I do so using: document.querySelector('div

javascript execCommand('delete') not delete all selection div in chrome

我的梦境 提交于 2019-12-12 10:48:40
问题 I try to write an editor with contenteditable & execCommand Everything works fine on Firefox, but in chrome has an error with 'delete' command. Please view bellow photo: This is my code: var $obj = $('#myBlockDivId'); var selection = rangy.getSelection(); if (selection.rangeCount > 0) selection.removeAllRanges(); var range = rangy.createRange(); range.selectNode($obj[0]); selection.addRange(range); range.select(); when i console log: rangy.getSelection().toHtml() ==> it's right but when i

WYSIWYG again, IE simplest execCommand

99封情书 提交于 2019-12-11 15:55:37
问题 I wrote the simplest WYSIWYG in js/jquery: http://jsfiddle.net/XnSWF/ Works perfectly (eg. set to write in bold or set bold on selected text) on newset Opera 11, Chrome 16, Firefox 9 and Safari 5.1 but in IE9 I can't set bold to selected text and always when i use bold button, this carret go to first line to first letter... Why? 回答1: It's because the selection is destroyed before the click event fires in IE. You can get round this by using the the mousedown event instead, or (better) by

copy command using JS

…衆ロ難τιáo~ 提交于 2019-12-11 07:32:14
问题 Please help me solve this code. I've been fixing this for a month. Thank you for helping! function copyText(text) { text.select(); try { document.execCommand('copy'); } catch (err) { console.log('Unable to copy' + err); } } copyText('JS is love'); 回答1: The .select() function call doesn't belong to strings but instead HTMLInputElement such as TextArea document.execCommand('copy') can only run as a result of an user action. In other words, it must belong inside an EventListener such as 'click'

execCommand(“Print”, false, IDon'tUnderstandThisArgument)

邮差的信 提交于 2019-12-11 05:26:16
问题 What I'm trying to do is get this to print in landscape mode without showing the dialog box. This is what I have so far: ((mshtml.IHTMLDocument2)Browser.Document.DomDocument).execCommand("Print", true, 0); I know that the instruction to print in landscape mode needs to be sent through the third argument, but I don't know how to construct the third argument to do this. Can anyone give me some help on how to make this last argument accomplish my goal? 回答1: ADDITIONS: This is from Microsoft http