I’m writing on objective-C.
I have WebView and local file index.html has
<a href='http://www.google.com' name="666">
How can I get the name attribute?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on when/by what you need to get the name. If you need the name when someone clicks on the link, you can set up some JavaScript that runs when the link is clicked (onclick handler). If you just have the html string, you can use regular expressions to parse the document and pull out all of the name attributes. A good regular expression library for Objective-C is RegexKit (or RegexKitLite on the same page).
The regular expression for parsing the name attribute out of a link would look something like this:
EDIT: The javascript for getting a name out of a link when someone clicked it would look something like this:
This would be called from the
onclickhandler, something like:If you need to get the name back to your Objective-C code, you could write your onclick function to append the name attribute to the url in the form of a hashtag, and then trap the request and parse it in your UIWebView delegate’s
-webView:shouldStartLoadWithRequest:navigationType:method. That would go something like this: