Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How do I use Javascript to tell Safari to enter text?

Reply
Thread Tools

How do I use Javascript to tell Safari to enter text?

 
 
David
Guest
Posts: n/a
 
      12-26-2004
Safari under Mac OSX accepts a "Execute Javascript" apple event. Thus,
you can send an event to if from another application (or from the
Scripts menu).

I would like an event that does the equivalent of "set selection", so I
can fill in some text in a text entry box. In particular, I have a visa
card number stored in the Keychain database. I retrieve it with an
Applescript, then would like to execute the equivalent of "do
javascript "document.setSelection('1234-3456-4567-5678');"

I do not know Javascript and have not tripped over anything that looks
promising to do this. What I need is the syntax (if this is even
possible!) for the document.setSelection" command. What I want this to
do is output the text where the cursor currently is. [I can do this now
with as outputting keystrokes, but that is just so ugly!]

Any help would be greatly appreciated.

David

PS: if you want to contact me directly, I'm on mac.com with user name
dhoerl

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-26-2004


David wrote:


> I do not know Javascript and have not tripped over anything that looks
> promising to do this. What I need is the syntax (if this is even
> possible!) for the document.setSelection" command.


Well if the document object has a method named setSelection then the
syntax to call it is
document.setSelection()
if the method takes a string argument then you have the right syntax
already e.g.
document.setSelection('1234-3456-4567-5678');

But I don't think that is a syntax problem, it seems what you are after is

> What I want this to
> do is output the text where the cursor currently is.


the right object and the right method name. Those depend on the browser,
at least for some non-standardized stuff like text selection and its
manipulation.
As far as I know Safari so far has no API exposed to JavaScript to
manipulate the selection.
If they have one chances are they have tried to be compatible with an
existing API, MSIE/Win has one documented here:
<http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_selection.asp>
So there you could do
if (document.selection && document.selection.createRange) {
document.selection.createRange().text = '1234-3456-4567-5678';
}
I do not have access to a Mac currently so you would need to try that
yourself.

Mozilla also has an API to manipulate the text selection but there are
different APIs there really, one exposed on text controls and one for
text rendered on the page. So with Mozilla you would need to know which
control you want to insert text into.
Example code is here:
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>
Again you would need to test that with Safari yourself.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Safari enter/return bypassing my button script Tim Streater Javascript 7 06-13-2007 09:13 PM
Safari and the Enter key wolis Javascript 0 10-10-2006 06:10 AM
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
Does anyone know why Safari browser does not submit on enter key. zazzaron@cox.net HTML 1 12-20-2005 07:50 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57