Re: Getting WebKit Form Values
Re: Getting WebKit Form Values
- Subject: Re: Getting WebKit Form Values
- From: Nicko van Someren <email@hidden>
- Date: Tue, 3 Feb 2004 17:44:33 +0000
On 3 Feb 2004, at 15:52, Laurent Daudelin wrote:
On 03/02/04 10:38, "Josh Ferguson" <email@hidden> wrote:
I'm currently trying to (essentially) script a browser session using
webkit.
I'm not looking to be able to script any page - just my specific
content. Is
there a way to fetch values from an HTML form when a specific button
is
clicked? Is there a way to know which button on the form was
clicked? Also,
is there a way to associate a specific control in a WebView with its
corresponding HTML id? If you have the answers to any of these
questions, I'd
greatly appreciate it. So far I'm somewhat disappointed in the
limitations of
WebKit. Cool technology demo, poor flexibility.
Not sure about detecting when a specific button is clicked. However,
in the
frameLoadDelegate of your webview, implements
'webView:didFinishLoadForFrame:'. Then, use some Javascript embedded
in an
NSString like the following to access any item on the form:
returnString = [myWebView
stringByEvaluatingJavaScriptFromString:[NSString
stringWithFormat:@"document.forms[0].os0.value=\"%@\"", aValue]];
os0 here is the name of a textfield in the form. When the page is
displayed,
the textfield contains 'aValue'. That works pretty well...
One ugly but probably effective way to detect the user clicking on a
button would be to make the action for the form target some URL with a
special protocol (e.g <form method="GET" action="myprotocol:/stuff">)
and then register your own NSURLProtocol which will get called when the
user uses this.
A much better way to do this would be for the WebKit framework to allow
programmers to register their own JavaScript functions, as Internet
Exploder does with the windows.external.<function>(...) system.
Perhaps this is already there and I just don't know how to do it (can
someone from Apple let us know?). Of course if they did this then we
could write Safari plug-ins that would do cool things like
cryptographic form signing a la Netscape/Mozilla, and the world would
be a better place for it.
Nicko
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.