getSelection() for iPhone bookmarklet

孤街浪徒 提交于 2019-12-11 06:41:40

问题


I've done a bit of research but can't seem to find a definitive answer regarding getting the currently selected text via getSelection() in an iPhone bookmarklet. Is this still possible? It seems that from various searches there are a number of bookmarklets available that use a similar behaviour, but none appear to work for me.

I'm simply selecting some text on my iPhone, waiting for the draggable box to appear (along with the Copy button) and then tapping the Bookmark icon in MobileSafari and selecting the bookmarklet of my choice.

To grab the currently selected text I'm doing something like this:

encodeURIComponent( window.getSelection ? window.getSelection()+'' : (document.getSelection) ? document.getSelection()+'' : (document.selection ? document.selection.createRange().text+'' : 0) )

Does anyone have any experience with this?


回答1:


I assume you've tried similar suggestions to this blog post. Possibly some more description here. Sorry they're just links, I don't know too much about this, but I'm interested in the solution.

document.selection.createRange().text is another option.

Have a look at Range objects, too.



来源:https://stackoverflow.com/questions/1936132/getselection-for-iphone-bookmarklet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!