On 28.9.2009, at 10:09, Philip Juel Borges wrote:

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"];
}


You need to execute full statement:

NSString *command = [NSString stringWithFormat:@"goToPage( '%@' );", [sender stringValue]] ;
[theWebView stringByEvaluatingJavaScriptFromString:command] ;


and this:

- (IBAction)runJavaScript:(id)sender {
[[theWebView windowScriptObject] callWebScriptMethod:@"goToPage" withArguments:nil];
}



Again, there are no arguments. How could it work? Try this:

[[theWebView windowScriptObject] callWebScriptMethod:@"goToPage" withArguments:[NSArray arrayWithObject:[sender stringValue]]];



Regards,

izidor

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to