execcommand

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

江枫思渺然 提交于 2019-11-28 09:26:44
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? 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().focusNode.parentNode; $(listId).addClass("oder2"); } </script> .oder2 { padding-left: 3em; } I got the

set execcommand just for a div

不想你离开。 提交于 2019-11-28 04:47:40
it has any way for bind execcommand with a div element not for whole document , i try this : document.getElementById('div').execcommand(...) but it has an error : execcommand is not a function it has any way for bind the execcommand with just div element not whole document !! i don't like use iframe method . This is easier to do in IE than other browsers because IE's TextRange objects have an execCommand() method, meaning that a command can be executed on a section of the document without needing to change the selection and temporarily enable designMode (which is what you have to do in other

execCommand insertHTML breaks stored window.getSelection()

江枫思渺然 提交于 2019-11-27 09:52:18
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 endOffset sets itself to the same value as the selections startOffset Is there a reason for this? More

Cannot use `document.execCommand('copy');` from developer console

£可爱£侵袭症+ 提交于 2019-11-27 09:01:59
Calling document.execCommand('copy'); from the Chrome developer console returns false every time. Give it a try yourself. Open the console and run it, it never succeeds. Any idea as to why? document.execCommand('copy') must be triggered by the user. It's not only from the console, it's anywhere that's not inside an event triggered by the user. See below, the click event will return true, but a call without event won't and a call in a dispatched event also. console.log('no event', document.execCommand('bold')); document.getElementById('test').addEventListener('click', function(){ console.log(

window.getSelection return html [duplicate]

淺唱寂寞╮ 提交于 2019-11-27 08:47:41
This question already has an answer here: HTML of selected text 1 answer function selected() { var selObj = window.getSelection(); } This function returns selected text from a webpage. How do return the html of a selected area. Is this possible to do with an <img> and an <a> tag? Here's the list of functions: https://developer.mozilla.org/Special:Tags?tag=DOM&language=en Tim Down The following will do this in all major browsers and is an exact duplicate of this answer : function getSelectionHtml() { var html = ""; if (typeof window.getSelection != "undefined") { var sel = window.getSelection()

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

谁说我不能喝 提交于 2019-11-27 06:12:44
问题 (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 =

Cross-browser Save As .txt

别来无恙 提交于 2019-11-27 05:21:21
Is there a JavaScript library that allows to save strings as txt files, and works cross-browser? In the past, I have been using Downloadify, but I am looking at another option for a couple reasons: I hope to find a pure JavaScript solution, without the need for Flash it seems that Downloadify is not updated anymore (no update in the past 18 months) I am experiencing an issue with Downloadify in IE 9, where strings are cut off As far as I know, the only way is to use data: URLs to force a download: var data = "This is a test"; window.location.href = "data:application/x-download;charset=utf-8,"

document.execCommand() FontSize in pixels?

丶灬走出姿态 提交于 2019-11-27 04:50:33
How can I change font size to 30px (for example) using document.execCommand ? This: document.execCommand("fontSize", false, "30px"); doesn't work, because in 3rd argument of the function execCommand, it only allows me to input a value between and including 1 to 7. It's a limitation of the FontSize command. There are various options I can think of: You could use a CSS class instead and use the CSS class applier module of my Rangy library; You could use a hacky method, such as calling document.execCommand("fontSize", false, "7"); and then finding the elements the command has created and changing

set execcommand just for a div

旧街凉风 提交于 2019-11-27 00:31:49
问题 it has any way for bind execcommand with a div element not for whole document , i try this : document.getElementById('div').execcommand(...) but it has an error : execcommand is not a function it has any way for bind the execcommand with just div element not whole document !! i don't like use iframe method . 回答1: This is easier to do in IE than other browsers because IE's TextRange objects have an execCommand() method, meaning that a command can be executed on a section of the document

Cannot use `document.execCommand(&#39;copy&#39;);` from developer console

社会主义新天地 提交于 2019-11-26 14:27:10
问题 Calling document.execCommand('copy'); from the Chrome developer console returns false every time. Give it a try yourself. Open the console and run it, it never succeeds. Any idea as to why? 回答1: document.execCommand('copy') must be triggered by the user. It's not only from the console, it's anywhere that's not inside an event triggered by the user. See below, the click event will return true, but a call without event won't and a call in a dispatched event also. console.log('no event',