从另一个框架获取选定的文本

发布于 2024-07-17 03:07:46 字数 321 浏览 3 评论 0原文

我有一个框架集,我希望有人能够单击一个框架中的按钮,该按钮可以对另一个框架中选择的文本执行某些操作。 frame[0] 中的按钮调用以下 JavaScript 以从 frame[1] 获取所选文本:

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

我认为,问题在于单击frame[0] 中的按钮取消选择 frame[1] 中的文本,因此 getSelection 返回一个空字符串。 对此我能做什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2024-07-24 03:07:46

尝试使用 onmousedown 而不是 onclick 作为按钮的处理程序。 我相信它会在焦点被赋予按钮并且选择丢失之前得到处理。

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.

辞取 2024-07-24 03:07:46

你的问题出在别的方面。 先前的选择会保留足够长的时间,以便在单击时进行记录。 它可能会帮助您查看执行您想做的事情的工作代码。

我为 FCKEditor。 它可能看起来很复杂,但基本上它会执行您想要的操作:用户选择某些内容,单击按钮,编辑器对单击做出反应并执行 此 JavaScript。 该代码使用一些 FCKEditor 函数来进入编辑窗口,但是您对这部分不感兴趣。

最重要的是,你的计划有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文