How to use the new Android M feature of “Text Selection” to be offered from outside of your app?

First, to clarify the question: On an M emulator, if you highlight text, you will see the new floating action mode. If you click the overflow icon, you will see “API DEMOS” show up: Clicking that brings up an activity from the API Demos app, showing the highlighted text: Replacing the value in the field … Read more

Set cursor to specific position on specific line in a textarea

I’ve updated your fiddle see: http://jsfiddle.net/eghpf/2/ I’ve added var currentPosition which is used in this method function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd(‘character’, selectionEnd); range.moveStart(‘character’, selectionStart); range.select(); } } Which comes from this jQuery Set Cursor Position in Text Area … Read more

Return HTML from a user-selected text

Here’s a function that will get you HTML corresponding to the current selection in all major browsers: function getSelectionHtml() { var html = “”; if (typeof window.getSelection != “undefined”) { var sel = window.getSelection(); if (sel.rangeCount) { var container = document.createElement(“div”); for (var i = 0, len = sel.rangeCount; i < len; ++i) { container.appendChild(sel.getRangeAt(i).cloneContents()); … Read more

How to make HTML Text unselectable [duplicate]

You can’t do this with plain vanilla HTML, so JSF can’t do much for you here as well. If you’re targeting decent browsers only, then just make use of CSS3: .unselectable { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } <label class=”unselectable”>Unselectable label</label> If you’d like to cover older browsers … Read more

Is there a way to make text unselectable on an HTML page? [duplicate]

In most browsers, this can be achieved using CSS: *.unselectable { -moz-user-select: -moz-none; -khtml-user-select: none; -webkit-user-select: none; /* Introduced in IE 10. See http://ie.microsoft.com/testdrive/HTML5/msUserSelect/ */ -ms-user-select: none; user-select: none; } For IE < 10 and Opera, you will need to use the unselectable attribute of the element you wish to be unselectable. You can set … Read more

How to get selected text from a textbox control with JavaScript

OK, here is the code I have: function ShowSelection() { var textComponent = document.getElementById(‘Editor’); var selectedText; if (textComponent.selectionStart !== undefined) { // Standards-compliant version var startPos = textComponent.selectionStart; var endPos = textComponent.selectionEnd; selectedText = textComponent.value.substring(startPos, endPos); } else if (document.selection !== undefined) { // Internet Explorer version textComponent.focus(); var sel = document.selection.createRange(); selectedText = sel.text; … Read more