getselection

IE 8 getSelection().anchorOffset alternative

余生长醉 提交于 2019-12-20 05:59:27
问题 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? 回答1: 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

What's the best way to set cursor/caret position?

眉间皱痕 提交于 2019-12-17 10:17:23
问题 If I'm inserting content into a textarea that TinyMCE has co-opted, what's the best way to set the position of the cursor/caret? I'm using tinyMCE.execCommand("mceInsertRawHTML", false, content); to insert the content, and I'd like set the cursor position to the end of the content. Both document.selection and myField.selectionStart won't work for this, and I feel as though this is going to be supported by TinyMCE (through something I can't find on their forum) or it's going to be a really

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

Javascript functions return lines of function code or “{[native code]},” what am I doing wrong?

社会主义新天地 提交于 2019-12-13 04:43:57
问题 I am writing some code to find the user selection in a contenteditable div, I'm taking my code from this quirksmode article. function findSelection(){ var userSelection; if (window.getSelection) {userSelection = window.getSelection;} else if (document.selection){userSelection = document.selection.createRange();} // For microsoft if (userSelection.text){return userSelection.text} //for Microsoft else {return userSelection} } I'm testing it in Chrome and Firefox, if I do an alert(userSelection)

How to get selected text with JavaScript

一笑奈何 提交于 2019-12-12 07:20:07
问题 I'm a little confused why doesn't this code work! The HTML Markup: <div id="diva"><b>Score</b> some <i>goals</i></div> <div id="soda"></div> The JavaScript code: function GetSelectedText () { if (window.getSelection) { // all browsers, except IE before version 9 var range = window.getSelection (); alert (range.toString ()); } else { if (document.selection.createRange) { // Internet Explorer var range = document.selection.createRange (); alert (range.text); } } } var butn = document

Can't get Position&Container Infomation by Click the iPad

独自空忆成欢 提交于 2019-12-12 05:06:43
问题 In chrome or Safari browser, when I select the text on the page I can get the Selection-info by window.getSelection() , And it worked on iPad too. But when I just click , in browser, I will get a window.getSelection (isCollapsed==true) with full infomation about the position and container . In iPad it just tell you the selection isCollapsed but the position info is 0 or null . Anyone have an idea how to get the container and the position info when you click in iPad? 回答1: Basically using touch

JavaScript / jQuery: get selection function not working in Firefox and Chrome

て烟熏妆下的殇ゞ 提交于 2019-12-11 14:34:03
问题 I am using the following function to get the selected text (i.e. text selected by the user) in a contenteditable div. This works perfect in IE 9 but not in IE 8, Firefox or Chrome (both latest versions). Can someone here help me to modify this in a way that it works at least in Firefox and IE 8 as well (Chrome is not a must) ? My function (working): function GetSelection() { selTxt = ''; if (typeof window.getSelection != "undefined") { var sel = window.getSelection(); if (sel.rangeCount) {

get data from selected slice of google charts PieChart

半城伤御伤魂 提交于 2019-12-11 12:12:44
问题 i have big trouble trying to get the value of the selected slice of a PieChart when its clicked. The documentation says: selection_array: An array of selected objects, each one describing a data element in the underlying table used to create the visualization (a DataView or a DataTable). Each object has properties row and/or column, with the index of the row and/or column of the selected item in the underlying DataTable. If the row property is null, then the selection is a column; if the

Android: problems with getSelectedItem on a spinner

 ̄綄美尐妖づ 提交于 2019-12-11 10:42:20
问题 I have a Spinner , and put the selected item in the body of a mail. this is my code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_modulo); Spinner spinnerTaglia = (Spinner) findViewById(R.id.spinnerTaglia); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Taglie, android.R.layout.simple_spinner

JavaScript / jQuery: how to get selected text in Firefox

三世轮回 提交于 2019-12-11 08:23:30
问题 how can I get the selected text (in a contenteditable div) in Firefox ? It would be enough for recent versions, no need to cover old versions. Say I have a contenteditable div that looks like the below and someone selects a text there and then hits a button, how can I copy the selected text to the clipboard or a variable ? Example: <div class='editInput' id='editInput'>Some awesome text</div> My current function (working in IE): function GetSelection() { if (typeof window.getSelection !=