Re: copy in WebView
Re: copy in WebView
- Subject: Re: copy in WebView
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sat, 13 Oct 2012 23:47:40 +0700
On 13 Oct 2012, at 21:30, Keary Suska <email@hidden> wrote:
> On Oct 13, 2012, at 5:12 AM, Gerriet M. Denkmann wrote:
>
>>
>> On 12 Oct 2012, at 23:02, Kyle Sluder <email@hidden> wrote:
>>
>>> On Oct 12, 2012, at 1:47 AM, "Gerriet M. Denkmann" <email@hidden> wrote:
>>>
>>>>
>>>> I managed (using: <body oncopy="return MyJavaScriptFunction()">) to get the selection and modify it (removing unwanted characters) but I do not know how to put the resulting string onto the clipboard.
>>>
>>> That should be sufficient to get the right string on the clipboard. You've modified the DOM, and now the browser will copy the text from the DOM to the pasteboard.
>>
>> No, I have not modified the DOM.
>> I did:
>> var t0 = window.getSelection();
>> var t1 = String(t0);
>> then I removed the unwanted chars from this string.
>> Then I wanted to put the cleaned up string to the pasteboard, but failed.
>
>
> You could use a WebScriptObject (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/WebKit/Classes/WebScriptObject_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003820) to call you JavaScript and put the results on the clipboard...
Interesting idea.
But I have chosen another way:
The Edit → Copy Menu does not send copy: to the first responder, but to the app delegate, which then checks if the first responder is my WebView (in which case it gets the selection, cleans it up and puts it on the pasteboard) or not (in which case it just sends copy: to it).
Works fine - no problems so far.
Well, there is one small problem:
This line:
if ( [ targetForCopy isKindOfClass: NSClassFromString (@"WebHTMLView") ] ) then do my own stuff...
has this undocumented WebHTMLView.
So if Apple changes WebKit to use WebNewAndBetterHTMLView then my code will break.
But I guess (and hope) that this is not too likely.
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden