Page 1 of 1

Example of Javascript Function for setTextSelectionRange

Posted: Fri May 09, 2008 8:58 am
by mallir
Hi,

I'm having problems trying to call setTextSelectionRange() via javascript in the browser. I am able to call getTextSelectionRange() and get the coordinates of selected text.
I would like to be able to set the selected text via a javascript function. I'm not sure how to handle the "sel" object and what arguments to pass. Would you happen to have an example?

Thank you.

Bob

Re: Example of Javascript Function for setTextSelectionRange

Posted: Fri May 09, 2008 11:14 am
by jaymz
mallir wrote:I'm having problems trying to call setTextSelectionRange() via javascript in the browser.
I'm not sure how to handle the "sel" object and what arguments to pass. Would you happen to have an example?
Documentation for that method is found here:
http://print2flash.com/help/DocumentAPI ... ctionRange

...and here's an example that I whipped up that I hope will help you get started. Just treat the argument to the set method like a native JavaScript object:

Code: Select all

document.getElementById('p2fDoc').setTextSelectionRange({
    headPageIdx: 1,
    headCharIdx: 3,
    tailPageIdx: 1,
    tailCharIdx: 21
});
In case it's not obvious, this example selects the text on page one from character 3 to character 21.

Re: Example of Javascript Function for setTextSelectionRange

Posted: Fri May 09, 2008 11:38 am
by mallir
Hi Jay,

Thanks alot for the snippet. This worked for me.

Also, FYI for anyone else; you can select the entire document by setting the range to a large number such as follows:

document.getElementById('Print2FlashDoc').setTextSelectionRange({
headPageIdx: 1,
headCharIdx: 0,
tailPageIdx: 100,
tailCharIdx: 999999
});

Thanks again,

Bob