Can't get WebView to work with JavaScript communication
Can't get WebView to work with JavaScript communication
- Subject: Can't get WebView to work with JavaScript communication
- From: "Theodore H. Smith" <email@hidden>
- Date: Wed, 11 Jan 2006 22:21:23 +0000
I can't seem to get JavaScripts to call my Obj-C objects. And I can't
get my Obj-C to call the JavaScript either!!
Only the delegate functions work, not any cross JS/ObjC communication.
I got a test using this JavaScript:
ARGH_JAM_TEST = function (testStr) {
alert( testStr );
};
I'm testing it with this code:
-(void)LoadSub:(NSURL*) u {
[MyWebView setUIDelegate:self];
[MyWebView setFrameLoadDelegate:self];
NSURLRequest* request = [NSURLRequest requestWithURL:u];
[[MyWebView mainFrame] loadRequest: request];
}
- (void)webView:(WebView *)sender windowScriptObjectAvailable:
(WebScriptObject*)scr {
NSArray* args = [NSArray arrayWithObject:@"CocoaLoadSub success!"];
id Result = [scr callWebScriptMethod:@"ARGH_JAM_TEST"
withArguments:args];
[scr setValue:self forKey:@"MacJamPlayer"];
}
This should give me a msgbox saying "CocoaLoadSub success".
My msgboxes ARE called by JavaScript, as I'm implementing that
delegate. This code will msgbox just fine:
ARGH_JAM_TEST( "internal success" ); // code is at the script level,
outside of any function
So the function is being called, and it msgboxes correctly.
So why can't my JavaScript call it??????
I even went to the trouble of implementing this
windowScriptObjectAvailable delegate method. In fact it didn't work
whether I put that "callWebScriptMethod" call in a delegate, or
immediately after calling "loadRequest".
Is it because I'm still trying to set JavaScript stuff before the
JavaScript is loaded?? When does the JavaScript get loaded up? I'd
like to set some variables, before any JavaScript runs, even stuff on
the script level.
Any help anyone? A working example of Java communication would be
perfect.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden