Using getSelection() with content in frames
Sunday 12/28/2008 – Category: Uncategorized
An iPhoneSender user recently reported a bug with the Safari bookmarklet not correctly grabbing the selection and suspected it was because the selected content was in frames.
After some digging around, it turns out he was right--if your selection is in a frame, the normal window.getSelection() method will return nothing; you'll need to target the specific frame instead. We don't know the frame's name so we can't target it with parent.frames["framename"], but what we can do is just loop over all the frames in the document until we find it.
(simplified and expanded):
Leave a Reply
Recent Posts
- LED Light for iPhone 4
(Monday 06/28/2010 – 38 Comments) - WWDC 2010: Worth Every Minute
(Monday 06/14/2010 – No Comments) - Flickr Original for Safari 5!
(Wednesday 06/9/2010 – 15 Comments) - iPad thoughts
(Friday 04/2/2010 – 1 Comment)
