Blog Communities Publishing Magazines

« How Opera Competes with Firefox | Main | Onfolio Syncs with Bloglines »

April 24, 2005

getSelection() Workaround for Safari 1.3 and Firefox 1.0.3

Here's a good workaround for some javascript problems.

Yesterday morning I noticed a change to the JavaScript/DOM getSelection() behavior in the new Safari 1.3 (in 10.3.9) and the most recent version of Firefox 1.0.3.

What Safari and Firefox now seem to be doing is creating a DOM selection object from getSelection() instead of treating it as a simple string. The result is that getSelection() appear to be a string, but few of the string manipulation functions work without additional considerations.

Further inconsistencies between Safari 1.3 and Firefox 1.0.3:

Fails silently in Safari, returns selected text in Firefox. Safari dumps this into the Console log:

I was using the length property to determine whether a selection was empty or not, then fetching the title of the window if that value was 0. Knowing that length no longer works in Firefox and Safari, isCollapsed can be used as a conditional switch.

 

Related Products:
Visit our store

Read more from this blogger:
getSelection() Workaround for Safari 1.3 and Firefox 1.0.3

Posted on April 24, 2005 03:22 AM by Firefo84.
Filed in Firefox under firefox.
Permalink permalink | Comments (1)

Comments

Are you calling me a chump man? Well you are a punk.

Posted by: Roger Wray at July 20, 2007 04:18 PM

Post a comment




Remember Me?






Copyright 2005 Blog Carnival, LLC.
We welcome your feedback: Contact us!