• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Run Javascript Function From Objective-C.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run Javascript Function From Objective-C.


  • Subject: Re: Run Javascript Function From Objective-C.
  • From: Izidor Jerebic <email@hidden>
  • Date: Mon, 28 Sep 2009 11:00:15 +0200


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 (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


References: 
 >Run Javascript Function From Objective-C. (From: Philip Juel Borges <email@hidden>)

  • Prev by Date: Re: Master "addChildObject:" not called when adding child from an array controller !
  • Next by Date: NSTokenField token color
  • Previous by thread: Run Javascript Function From Objective-C.
  • Next by thread: Re: Run Javascript Function From Objective-C.
  • Index(es):
    • Date
    • Thread