views:

357

answers:

2

I have a frameset where I would like to have someone be able to click a button in one frame that does something with the text selected in the other frame. The button in frame[0] invokes the following javascript to get the selected text from frame[1]:

self.parent.frames[1].getSelection()

The problem, I believe, is that the very act of clicking on the button in frame[0] unselects the text in frame[1], so getSelection returns an empty string. What can I do about this?

+2  A: 

Try using onmousedown rather than onclick as the handler for the button. I believe it will get handled before focus is given to the button and the selection is lost.

Sean O Donnell
This fixed the problem - thanks!
A: 

Your problem is in something else. Previous selection survives long enough to be recorded on click. It may help you to look at the working code that does what you want to do.

I coded a smart quote plugin for FCKEditor. It may seem complicated, but basicly it does what you want: user selects something, clicks a button, editor reacts onclick and executes function from this javascript. The code uses some FCKEditor function to get to the edit window, but this part is of no interest for you.

Bottom line, your plan works.

buti-oxa