• 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
Using Objective-C From JavaScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using Objective-C From JavaScript


  • Subject: Using Objective-C From JavaScript
  • From: Chad Rosenberg <email@hidden>
  • Date: Thu, 10 Nov 2005 11:59:32 -0800 (PST)

I was trying to follow the "Using Objective-C From JavaScript" example on http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/ObjCFromJavaScript.html and I can't seem to get it to work. When I run the following:

function printNameAtIndex(index) {
    var myaddressbook = window.AddressBook;
    var name = myaddressbook.nameAtIndex_(index);
    document.write(name);
}

typeof(window.AddressBook) returns "function" and myaddressbook.nameAtIndex_ is undefinied.

I set up the AddressBook in an awakeFromNib method:

- (void)awakeFromNib
{
BasicAddressBook *littleBlackBook = [BasicAddressBook addressBook];
id win = [webView windowScriptObject];
[win setValue:littleBlackBook forKey:@"AddressBook"];


NSString* url = @"file:///tmp/test.html";
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];



NSLog(@"awake"); }

The above properly displays the test.html, and
[win setValue:littleBlackBook forKey:@"AddressBook"] seems to doing something, since without it "window.AddressBook" becomes undefined in the Java Script.


Any help would be appriciated.

Thanks,
Chad
_______________________________________________
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


  • Follow-Ups:
    • Re: Using Objective-C From JavaScript
      • From: Todd Ditchendorf <email@hidden>
  • Prev by Date: Re: NSLock locking order;
  • Next by Date: Re: NSArrayController/TreeController out of bounds
  • Previous by thread: Re: NSLock locking order;
  • Next by thread: Re: Using Objective-C From JavaScript
  • Index(es):
    • Date
    • Thread