Reputation: 3391
I am developing an app that contains a UIWebView. I want the user to be able to click on a UIButton (or UIButtonBarItem) that will trigger a div element within the UIWebView to toggle on and off (using jQuery - $('shade').toggle();
). Is this possible?
Names of elements..
UIWebView = forumIndex
UIButtonBarItem = forumMenuTrigger
The id of the div inside of the UIWebView = #shade
Upvotes: 0
Views: 173
Reputation: 56809
In the handler for UIButton
, you need to somehow grab the reference of the UIWebView
. I assume you can do that on your own.
Let forumIndex
be the name of the UIWebView
. Use - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
method to inject JavaScript into the UIWebView
.
[forumIndex stringByEvaluatingJavaScriptFromString: @"$('#shade').toggle();"];
Upvotes: 1
Reputation: 2445
Something like this should work.
Providing you have an IBAction set for when the UIButton is tapped you can do something in the IBAction method like this:
[self.webView stringByEvaluatingJavaScriptFromString:@"$('#shade').toggle();"];
I'm assuming here that your view controller has defined the webview as a property (in this case "webView") - replace it with whatever is appropriate.
Upvotes: 1