Re: Safari "do javascript" busted?
Re: Safari "do javascript" busted?
- Subject: Re: Safari "do javascript" busted?
- From: Richard Brosnahan <email@hidden>
- Date: Tue, 26 Apr 2005 10:54:28 -0400
Thanks to all for the hints. I was using the UI workaround, calling
Command C via System Events. It's less than ideal, as it clobbers the
clipboard, and can be unreliable.
Now I'm using this, based on hints from others:
set theResult to do JavaScript "unescape(getSelection())" in document 1
This also works:
set theResult to do JavaScript "unescape(window.getSelection())" in
document 1
I wonder if this will break when the next version of Safari is released.
--
Richard Brosnahan
Editor in Chief
Broz News
http://broznews.org
Forever is composed of nows.
Emily Dickinson, poet
On Apr 26, 2005, at 10:02 AM, email@hidden
wrote:
Hi Gary - in my tests, document.getSelection() always returns empty
string, even if wrapped in unescape. Calling window.getSelection
returns nil unless wrapped in unescape.
I don't know enough about javascript to know whether just calling
"getSelection()" without a variable implicitly refers to a particular
object. I just know wrapping getSelection() in unescape seems to
work around the problem at very little risk of changing the value of
the returned string.
Daniel
On Apr 25, 2005, at 6:37 PM, Listout wrote:
Daniel Jalkut <email@hidden>
Hi - I saw a similar problem discussed on the macscript mailing list.
In response to that issue I tinkered a bit and discovered that
modifying the javascript to use "unescape(getSelection())"
instead of
"getSelection()" seems to work around the problem.
For some reason Safari seems willing to return the text from unescape
but not from getSelection() directly.
Hope this helps,
Daniel
Pardon if this post is formatted oddly. I am using a web mail
client and the
editing field is about 40 characters wide. (Why do people invest
time in
something and then...oh, never mind.)
Daniel, I contributed some suggested JS code in that thread you
reference,
using unescape() and so forth. There may be a clue in that code to
make a
Safari experiment.
What I wonder (I don't use Safari) is whether there are any
differences when
you apply that method to different objects.
For instance, all the references that are being made lately show on
the
method. What happens if you target the 'window' versus the 'document'
object? (That method can work with a textarea or input as well, BTW.)
I think you could work an experiment like this (not tested, pseudo-
code):
if (! s = window.getSelection()) s = document.getSelection();
Now, the original code I submitted (I can't look right now) did an
object-model check too, like 'document.all', to branch around the 2
major
behaviors of locating an object in the tree.
Anyway, I just wonder if trying the getSelection() method on those
objects
yields any useful results.
--
Gary
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden