Run Javascript Function From Objective-C.
Run Javascript Function From Objective-C.
- Subject: Run Javascript Function From Objective-C.
- From: Philip Juel Borges <email@hidden>
- Date: Mon, 28 Sep 2009 10:09:35 +0200
Hi!
I have this javascript function in my test.html file which is loaded
in the WebView:
function goToPage(mybox) {
window.location ='#' + mybox.value;
}
It allows me to enter a number, like 24, which then goes to the anchor
tag <a name="24">. It serves the purpose of navigating a long html
file. It works perfectly if I type in the value in a textfield nested
inside test.html, like this <input type="text" style="font-size: 8px"
size=3 maxlength="2" onchange="goToPage(this)"/>.
I would rather do this with an NSTextField. I tried connecting the
first method and then other to the NSTextField, but it doesn't work:
- (IBAction)runJavaScript:(id)sender {
[theWebView stringByEvaluatingJavaScriptFromString:@"goToPage"];
}
and this:
- (IBAction)runJavaScript:(id)sender {
[[theWebView windowScriptObject] callWebScriptMethod:@"goToPage"
withArguments:nil];
}
But neither methods work. Any ideas?
--Philip
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden