-2

I have two test pages: page M and Page NM. They are both identical, in that they have one input textbox. The only difference is that M has a meta tag, and NM doesn't.

The meta tag looks like this

<meta http-equiv="X-UA-Compatible" content="IE=10"/>

Of course, IE=9 or IE=8 would also work. The edit control could be a textbox, password, textarea, contenteditable div, what have you. I can always find the current caret position using either

document.getElementById('ControlName').selectionStart.toString()

or

window.getSelection().focusOffset.toString()

This doesn't work on the NM page. How can I get the caret position when there is no meta tag on a page? Thanks for looking

Freakishly
  • 1,533
  • 5
  • 32
  • 61
  • 2
    repost of http://stackoverflow.com/questions/263743/how-to-get-caret-position-in-textarea and http://stackoverflow.com/questions/235411/is-there-an-internet-explorer-approved-substitute-for-selectionstart-and-selecti and http://stackoverflow.com/questions/2628323/textarea-selectionstart-in-ie and........ you get the point :P – Sean Johnson Jun 28 '12 at 00:44
  • 1
    Turn off compatibility view. http://blogs.msdn.com/b/ie/archive/2009/06/17/compatibility-view-and-smart-defaults.aspx – gilly3 Jun 28 '12 at 00:49
  • Sean, I used those questions to get to where I am now. But I find those solutions useless when the meta tag is not present in IE. I was hoping this question could stand by itself for a page that doesn't have a meta tag. – Freakishly Jun 28 '12 at 01:23

1 Answers1

1

I believe that that particular method is a non-standard, IE-only mechanism of getting the caret position. See this gist, a nice plugin for jQuery, which will accomplish what you are trying to do in IE 8, 9, or 10 and any other modern browser.

Lusitanian
  • 11,012
  • 1
  • 41
  • 38