0

As title said, i want to check wether the selected text is paragraph or belong to two different paragraph or an inline text,

I am using this java script code for getting text.

var range = window.getSelection().getRangeAt(0);
    var selectionContents = range.extractContents();

So need to check for selectionContents. Thanks in advance.

Ishu
  • 12,797
  • 5
  • 35
  • 51
  • What's the difference between inline text and paragraph? – Godwin Nov 28 '11 at 05:26
  • "this is inline text". here 'text' or 'is inline' i am referring for inline text and paragraph contains new line chars. – Ishu Nov 28 '11 at 05:29
  • sorry I get what inline text is, but what is an example of paragraph text? I'm not quite understanding you. – Godwin Nov 28 '11 at 05:33

1 Answers1

0

I suspect this isn't quite a full answer yet so I'll edit and explain further once it's more clear, but is this something like what you're looking for? http://jsfiddle.net/UFdDY/

[ getSelectionHtml() referenced from HTML of selected text ]

EDIT: Now take a look at the revision, it can tell the difference between inline text and an entire paragraph if this is what you're looking for, but it takes some modification to the html (assumes you're using server side script to generate the output).

http://jsfiddle.net/UFdDY/1/

Community
  • 1
  • 1
Godwin
  • 9,739
  • 6
  • 40
  • 58
  • Same condition happens by using these checks. it always create div that means go in this case if (typeof window.getSelection != "undefined") – Ishu Nov 28 '11 at 06:01
  • @Ishu, I'm sorry but I'm having a very difficult time understanding your English. – Godwin Nov 28 '11 at 06:12
  • sorry for that. what you are not understanding? – Ishu Nov 28 '11 at 06:16
  • Take a look at the revision, and again, I'm sorry but I did not understand your last comment at all. – Godwin Nov 28 '11 at 06:16
  • I have made these check which are mentioned in your link's answer. and these check is none of use for me.and in each case(selecting a word, line or a paragraph). it enters in if case which is(typeof window.getSelection != "undefined"). Hope now you can understand what i have tried and what i commented. – Ishu Nov 28 '11 at 06:20
  • That 'if' statement is a cross-browser check, so your browser will only enter one of the conditions. Please take some time and carefully clarify your question. I thought I understood but now I'm not sure. Provide some real examples with code. – Godwin Nov 28 '11 at 06:30
  • NO problem, actually i am not using any browser, it is in native iPhone app.Thanks for your try. – Ishu Nov 28 '11 at 06:38