window.getSelection on a jquery dialog box does not return the selection in Safari


I am using the jquery UI dialog ( ) to display a chunk of text. I want to select some text on this dialog box and manipulate it. Now my current code works on Chrome and Firefox but is not working on Safari. (Not tested on IE yet)

I get the selection and display it as follows:

selection = window.getSelection();

The alert returns zero on Safari. I am relatively new to javascript/jquery so any pointers will help! 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. Thanks everyone!

It looks like Safari works a little differently. The getSelection() is not returning a normal string object so not all the string methods work on the object it returns. This link has a work around

It looks like it is a very old "bug" so there may be better advise on what to do instead out there.