Using getSelection() with an iPhone bookmarklet

6 views
Skip to first unread message

Nial Giacomelli

unread,
Dec 20, 2009, 5:54:42 PM12/20/09
to iPhoneWebDev
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?

Reply all
Reply to author
Forward
0 new messages