On Jun 14, 10:15 am, Dimitris Papageorgiou <
foryou1...@gmail.com>
wrote:
> I want to test a GetSelection code.
>
> The code is the following:
>
> function GetSelectedText () {
> if (window.getSelection) { // all browsers, except IE before version 9
var range = window.getSelection ();
// I assume you meant this statement to be on a separate line.
> alert (range.toString ());
> }}
> This code assumes that a text segment is selected in a webpage.
> The console seems that it does NOT communicate/interact with the webpage where it is opened.
I'm unsure what makes you say this.
>
> How am i going to validate the above code?
The code above is a function declaration. When you put it in the
console it evaluates to |undefined| because the expression has no
value.
>
> I wrote the code in the console, selected text from the webpage, pressed the run command and what i get is *undefined*.
I believe this is the correct result.
If you want to run the function you have to call it. For that you can
use:
GetSelectedText();
or
(function GetSelectedText () { if (window.getSelection)
{ var range = window.getSelection(); alert
(range.toString ()); } })();
jjb