[英]window.getSelection on a jquery ui dialog does not return selection in Safari
I am using the jquery UI dialog ( http://jqueryui.com/demos/dialog/ ) to display a chunk of text.我正在使用 jquery UI 对话框( http://jqueryui.com/demos/dialog/ )来显示一段文本。 I want to select some text on this dialog box and manipulate it.
我想 select 这个对话框上的一些文本并对其进行操作。 Now my current code works on Chrome and Firefox but is not working on Safari.
现在我当前的代码适用于 Chrome 和 Firefox 但不适用于 Safari。 (Not tested on IE yet)
(尚未在 IE 上测试)
I get the selection and display it as follows:我得到选择并显示如下:
selection = window.getSelection();
alert(selection.toString().length);
The alert returns zero on Safari.警报在 Safari 上返回零。 I am relatively new to javascript/jquery so any pointers will help!
我对 javascript/jquery 比较陌生,所以任何指针都会有所帮助! Thank you!
谢谢!
Answer: For anyone seeing this... when I used the event "mousedown" instead of "click" in the dialog box on safari it started working.回答:对于看到这个的任何人......当我在 safari 的对话框中使用事件“mousedown”而不是“click”时,它开始工作。 Thanks everyone!
感谢大家!
It looks like Safari works a little differently.看起来 Safari 的工作方式略有不同。 The getSelection() is not returning a normal string object so not all the string methods work on the object it returns.
getSelection() 没有返回正常的字符串 object,因此并非所有字符串方法都适用于它返回的 object。 This link has a work around http://joemaller.com/503/getselection-workaround/
此链接可以解决http://joemaller.com/503/getselection-workaround/
It looks like it is a very old "bug" so there may be better advise on what to do instead out there.看起来这是一个非常古老的“错误”,因此可能会有更好的建议来代替那里做什么。
If you are doing anything with selections, I would strongly recommend that you take a look at Tim Down's rangy library.如果您正在对选择进行任何操作,我强烈建议您查看 Tim Down 的rangy库。 This guy is the Range/Selection object guru.
这家伙是范围/选择 object 大师。 His library does all the nitty gritty work of implementing a cross-browser range selection library.
他的库完成了实现跨浏览器范围选择库的所有细节工作。 The documentation is good and he is actively working on the project (v 1.1 came out a few days ago).
文档很好,他正在积极开展该项目(几天前发布了 v 1.1)。
(edit: I am NOT affiliated with the project. I just use it and love it!) (编辑:我不隶属于该项目。我只是使用它并喜欢它!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.