Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Workaround for a Safari 1.3 getSelection() problem Web Browsers
Safari 1.3 breaks AppleScripts that rely on the value of getSelection() from a do JavaScript call in Safari:
tell application "Safari"
  do JavaScript "getSelection()" in document 1
end tell
I discovered that by introducing another functional call around getSelection, Safari is coerced into returning the string as expected. There may be many possible calls that will fix this, but unescape() seems the most innocuous:
tell application "Safari"
  do JavaScript "unescape(getSelection())" in document 1
end tell
[robg adds: I haven't tested this one...]
    •    
  • Currently 2.80 / 5
  You rated: 5 / 5 (5 votes cast)
 
[7,351 views]  

Workaround for a Safari 1.3 getSelection() problem | 2 comments | Create New Account
Click here to return to the 'Workaround for a Safari 1.3 getSelection() problem' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Workaround for a Safari 1.3 getSelection() problem
Authored by: kildaer on Apr 26, '05 09:48:06AM

Wow this hint sounds like Chinese too me...

KLD


PS: I know this is not the most useful comment ever posted on this site ;-)



[ Reply to This | # ]
Workaround for a Safari 1.3 getSelection() problem
Authored by: joemaller on Apr 26, '05 03:56:41PM
I also posted a getSelection() workaround a few days ago. It's not really an AppleScript problem, rather a change in how Safari and Firefox handle the getSelection() function.

The gist is that Safari and Firefox both implemented security based changes to getSelection in their latest releases. Safari's update includes a bug which affects any string functions on the returned value of getSelection(). There are a few ways around this which work with older browser versions. The simplest is simply to add an empty string to the value (plus quote quote):

tell application "Safari"
  do JavaScript "getSelection()+''" in document 1
end tell
That immediately forces the getSelection() result into a string. From there everything should work normally.

Follow the link if you want more information.

[ Reply to This | # ]