In my webview i have a local webpage loaded, something like this,
function sendvalue(type, state) { window.external.sendMessage(type,state); } Show WC
In the webview its loaded like this,
-(void)gotWebview:(NSString *)pHTMLDoc{
[[[self pWebView] mainFrame] loadHTMLString:pHTMLDoc baseURL:nil];
[[self pWebView] setEditable:NO];
[[self pWebView] setNeedsDisplay:YES];
[[self pWebView] setFrameLoadDelegate:self];
[[self pWebView] setEditingDelegate:self];
}
To handle window.external, i tried to do something like this,
scriptObject = [self windowScriptObject];
[scriptObject setValue:self forKey:@"window.external"];
Even i tried with this one too,
- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowScriptObject forFrame:(WebFrame *)frame
{
[windowScriptObject setValue:self forKey:@"window.external"];
}
and the function to bind Objective C and JS
+(NSString*)webScriptNameForSelector:(SEL)sel
{
if(sel == @selector(sendMessage:))
return @"sendMessage";
return nil;
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)sel
{
if(sel == @selector(sendMessage))
return NO;
return YES;
}
After this, i was expecting if button is pressed , it should execute sendMessge written in the Objective C, but its not hitting,
Also need to mention, i will get the page from server, so its not possible to change it. basically i would like to know how to bind window.external in my webview, so i can hook these call, I have seen Embedded Webkit - script callbacks how? but didn't get what i was expecting.