Example of Javascript Function for setTextSelectionRange

Using Print2Flash Document API
Post Reply
mallir
Posts:2
Joined:Mon May 05, 2008 7:35 pm
Example of Javascript Function for setTextSelectionRange

Post by mallir » Fri May 09, 2008 8:58 am

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

jaymz
Posts:14
Joined:Mon Jan 28, 2008 4:29 pm

Re: Example of Javascript Function for setTextSelectionRange

Post by jaymz » Fri May 09, 2008 11:14 am

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.
Last edited by jaymz on Fri May 09, 2008 2:50 pm, edited 1 time in total.

mallir
Posts:2
Joined:Mon May 05, 2008 7:35 pm

Re: Example of Javascript Function for setTextSelectionRange

Post by mallir » Fri May 09, 2008 11:38 am

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

Post Reply