getselection

Get Chosen App from Intent.createChooser

血红的双手。 提交于 2019-12-04 06:25:08
I am trying to capture the result of Intent.createChooser to know which app a user selected for sharing. I know there have been a lot of posts related to this: How to know which application the user chose when using an intent chooser? https://stackoverflow.com/questions/6137592/how-to-know-the-action-choosed-in-a-intent-createchooser?rq=1 How to get the user selection from startActivityForResult(Intent.createChooser(fileIntent, "Open file using..."), APP_PICKED);? Capturing and intercepting ACTION_SEND intents on Android but these posts are somewhat old, and I am hoping that there might be

Javascript selected text highlighting prob

廉价感情. 提交于 2019-12-02 17:36:27
I have a html page with text content. On selecting any text and pressing the highlight button, I can change the style of the selected text to highlight the same. To implement this feature, i have written the following method. sel = window.getSelection(); var range = sel.getRangeAt(0); var span = document.createElement('span'); span.className = "highlight" + color; range.surroundContents(span); This is working fine if you choose a text with no html tag, but when the text has any html tag in between, it is giving error Failed to execute 'surroundContents' on 'Range': The Range has partially

IE 8 getSelection().anchorOffset alternative

僤鯓⒐⒋嵵緔 提交于 2019-12-02 09:16:56
I have got a Javascript code, which works well for modern browsers: var offset = getSelection().anchorOffset; var node = getSelection().anchorNode; How can I get the same result on IE 8, which does not have window.getSelection() method? There is a solution. It is possible to extend browser's object model using Rangy library: window.getSelection = rangy.getSelection As it may take some time for Rangy to init and as we will not need this for modern browsers, some more workaround: /* IE 8 getSelection() missing object and properties simple hack */ if (window.getSelection == undefined) { /* IE? */

Get the raw HTML of selected content using javascript

痞子三分冷 提交于 2019-12-01 03:17:45
问题 How would I get the raw HTML of the selected content on a page using Javascript? For the sake of simplicity, I'm sticking with browsers supporting window.getSelection . Here is an example; the content between both | represent my selection. <p> The <em>quick brown f|ox</em> jumps over the lazy <strong>d|og</strong>. </p> I can capture and alert the normalized HTML with the following Javascript. var selectionRange = window.getSelection().getRangeAt(0); selectionContents = selectionRange

Avoid createElement function if it's inside a <LI> element (contentEditable)

时光毁灭记忆、已成空白 提交于 2019-12-01 01:07:28
I'm using this function in order to replace <DIV>New Divs</DIV> with <BR> in break lines on contentEditable divs using Safari and Chrome: $("#form_description").live("keypress", function(e){ if (e.which == 13) { if (window.getSelection) { var selection = window.getSelection(), range = selection.getRangeAt(0), br = document.createElement("br"); range.deleteContents(); range.insertNode(br); range.setStartAfter(br); range.setEndAfter(br); range.collapse(false); selection.removeAllRanges(); selection.addRange(range); return false; } } }); The problem is that when I'm typing inside an <UL><LI

How to find the selection text beginning and end positions in Javascript?

给你一囗甜甜゛ 提交于 2019-11-30 23:34:39
I am trying to find the textual start and end of the selection. So, in the following text, if I selected "world! What a fine" from within "Hello, world! What a fine day it is!", I should get 7 as the start coordinate, and 24 as the end coordinate assuming a zero based index. How is this achievable? EDIT: I am looking to find the selection of text that is not inside any <input> or <textarea> elements. EDIT: Decided the solution to use disabled <textarea>s I use this: /* Returns 3 strings, the part before the selection, the part after the selection and the selected part */ function getSelected()

How to find the selection text beginning and end positions in Javascript?

南楼画角 提交于 2019-11-30 17:41:24
问题 I am trying to find the textual start and end of the selection. So, in the following text, if I selected "world! What a fine" from within "Hello, world! What a fine day it is!", I should get 7 as the start coordinate, and 24 as the end coordinate assuming a zero based index. How is this achievable? EDIT: I am looking to find the selection of text that is not inside any <input> or <textarea> elements. EDIT: Decided the solution to use disabled <textarea>s 回答1: I use this: /* Returns 3 strings,

how do I get co-ordinates of selected text in an html using javascript document.getSelecttion()

痞子三分冷 提交于 2019-11-30 06:28:54
问题 I would like to position element above selected text. But I am not able to figure out the coordinates. var sel = document.getSelection(); if(sel != null) { positionDiv(); } Example: (image) 回答1: Here is the basic idea. You insert dummy element in the beginning of the selection and get the coordinates of that dummy html element. Then you remove it. var range = window.getSelection().getRangeAt(0); var dummy = document.createElement("span"); range.insertNode(dummy); var box = document

how do I get co-ordinates of selected text in an html using javascript document.getSelecttion()

Deadly 提交于 2019-11-28 18:59:54
I would like to position element above selected text. But I am not able to figure out the coordinates. var sel = document.getSelection(); if(sel != null) { positionDiv(); } Example: (image) Here is the basic idea. You insert dummy element in the beginning of the selection and get the coordinates of that dummy html element. Then you remove it. var range = window.getSelection().getRangeAt(0); var dummy = document.createElement("span"); range.insertNode(dummy); var box = document.getBoxObjectFor(dummy); var x = box.x, y = box.y; dummy.parentNode.removeChild(dummy); 来源: https://stackoverflow.com

Need to set cursor position to the end of a contentEditable div, issue with selection and range objects

混江龙づ霸主 提交于 2019-11-27 23:15:59
I'm forgetting about cross-browser compatibility for the moment, I just want this to work. What I'm doing is trying to modify a script (and you probably don't need to know this) located at typegreek.com The basic script is found here . Basically what it does is when you type in characters, it converts the character your are typing into greek characters and prints it onto the screen. What I'm trying to do is to get it to work on contentEditable div's (It only works for Textareas) My issue is with this one function: The user types a key, it get's converted to a greek key, and goes to a function,