• 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
Run Javascript Function From Objective-C.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Run Javascript Function From Objective-C.
      • From: Izidor Jerebic <email@hidden>
  • Prev by Date: Re: Global Hotkeys in 64-bit mode
  • Next by Date: Re: Master "addChildObject:" not called when adding child from an array controller !
  • Previous by thread: Re: NSScreen Issues
  • Next by thread: Re: Run Javascript Function From Objective-C.
  • Index(es):
    • Date
    • Thread