execcommand

Save Selected Text Range for Use Later Not working

廉价感情. 提交于 2019-12-03 16:46:54
I am using contenteditable and highlighting some text. I want to then backup that text range, and at a later time give that range(text) a different color. If I check in my zss_editor.restorerange method I do get back a valid selection object, so it must be something incorrect in how I am previously saving that range. var zss_editor = {}; // The current selection zss_editor.currentSelection; zss_editor.backuprange = function(){ var selection = window.getSelection(); zss_editor.currentSelection = selection.getRangeAt(0); zss_editor.currentSelection.setEnd(zss_editor.currentSelection

can't use document.execCommand('copy') with input type file

给你一囗甜甜゛ 提交于 2019-12-02 11:43:30
can't copy the content of textarea to clipboard using the code below. <script> function copyText() { document.getElementById('in').click(); call(); } function call() { if(getComputedStyle(document.getElementById('butt')).opacity>0.5) {setTimeout(call,100);return;} var ta=window.document.createElement("textarea"); window.document.body.appendChild(ta); ta.value="this text should be in clipboard"; ta.focus(); ta.selectionStart=0; ta.selectionEnd=ta.value.length; ta.addEventListener('keypress', function(){window.document.execCommand('copy');}); var event = new Event('keypress'); ta.dispatchEvent

“execCommand” is not working with AngularJS

余生颓废 提交于 2019-12-02 07:43:39
In the process of creating my own mini/simplified text editor I ran into the issue of using execCommand. I do not know why my code isn't working. I tried to prevent the mousedown event and used the attribute "unsetectable="on" " but it still doesn't seem to work. Here's my code: <button type="button" class="btn btn-default" ng-click="makeBold()" unselectable="on" ng-mousedown="$event.stopPropagation()">B</button> and $scope.makeBold = function(){ document.execCommand('bold',false,null); }; Any help is appreciated, thanks! execCommand applies to the current selection. When you click the button

Unable to get document.execCommand('undo') working in the same manner across browsers

梦想与她 提交于 2019-11-30 16:20:48
I have some code implementing a context menu on a textbox, the context menu is to have an Undo and Redo item that calls the browsers native methods by using document.execCommand('undo') . This code functions as I require on Chromium based browsers but on FireFox and Opera the results are not as expected. My expectation is that undo and redo will function like the native browser context menu for an input element. The result is that the input elements do not undo and redo, however div elements with the contenteditable attribute set, do function as expected. So I'm wondering if this is a bug in

Definition of ExecCommand function for bold?

空扰寡人 提交于 2019-11-30 15:40:14
ExecCommand offers a way to bold text inside iFrame, make it italic, underline it etc. But it's missing an option to create <cite> or <strong> or <em> (there is formatBlock but only for block elements and not inline ones). I'd like to use ExecCommand function for creating <cite> - is there any way to achieve this? And obviously I want to maintain flawless parsing like in case of bold and not something like surroundContents which will fail when you use it twice on the same selection. I'm looking for a definition of ExecCommand bold command or a way to use existing commants to flawlessly add

JavaScript document.execCommand() own tags

邮差的信 提交于 2019-11-30 11:59:08
问题 I've found some really interesting! The execCommand function applies many useful features. But is it possible to work with OWN wraps? Like: document.execCommand("styleWithCSS", false, "<span class='own-class'>"); Everything related i've found was pretty old… so maybe one of you knows a good workaround or something. 回答1: Thanks to dandavis. The following works very well: document.execCommand("insertHTML", false, "<span class='own-class'>"+ document.getSelection()+"</span>"); 来源: https:/

How to get the image element after insert using execCommand?

荒凉一梦 提交于 2019-11-30 06:39:42
问题 Is there any way to get the image element after we insert the image using execCommand? for example e.execCommand('insertimage',0,'ronaldo.png') 回答1: Don't use insertimage , use plain old insertHTML and give the element you are inserting an ID so that you can reference it later. i.e., function insertHTML(img) { var id = "rand" + Math.random(); var doc = document.getElementById("editor"); doc = doc.document ? doc.document : doc.contentWindow.document; img = "<img src='" + img + "' id=" + id + "

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

邮差的信 提交于 2019-11-30 04:57:15
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="true"> some <span id="myId">hi</span> content </div> When, however, I insert the exact same html

Unable to get document.execCommand('undo') working in the same manner across browsers

混江龙づ霸主 提交于 2019-11-29 23:37:50
问题 I have some code implementing a context menu on a textbox, the context menu is to have an Undo and Redo item that calls the browsers native methods by using document.execCommand('undo') . This code functions as I require on Chromium based browsers but on FireFox and Opera the results are not as expected. My expectation is that undo and redo will function like the native browser context menu for an input element. The result is that the input elements do not undo and redo, however div elements

execCommand('copy') does not work in Ajax / XHR callback?

心已入冬 提交于 2019-11-29 06:50:51
(Tested using Chrome 44) Desired behaviour : Make XHR request, put result in text area, select text, and copy to clipboard. Actual behaviour : On successful XHR request, puts the result in text area and selects it, but fails to copy result to clipboard. But if I initiate the copy outside of the XHR callback, it works. Example html page: var selectAndCopy = function() { // Select text var cutTextarea = document.querySelector('#textarea'); cutTextarea.select(); // Execute copy var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log(