• 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: Interaction with web javascript & cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Interaction with web javascript & cocoa


  • Subject: Re: Interaction with web javascript & cocoa
  • From: Joseph Crawford <email@hidden>
  • Date: Tue, 20 Jan 2009 17:53:59 -0500

what i did is created the outlet to my webview, made the webview load an html file that contains all my JS functions and then call it like so.

NSString *command = [[NSString alloc] initWithFormat:@"addMarkerAtPoint(%f, %f, 13, \"%@\");", [location latitude], [location longitude], [location name]];
[mapOutlet sendMapCommand:command];


Now that sendMapCommand is a method I put in my mapController, here it is

-(void)sendMapCommand:(NSString *)cmd
{
    id map = [mapView windowScriptObject];
    [map evaluateWebScript:cmd];
}

The ONLY downfall to this is that you can only make 1 function call per command sent. I tried to do seperate calls and it would not work. Combining the calls into functions and making 1 function call has worked for me.

Thanks,
Joseph Crawford

On Jan 20, 2009, at 5:27 PM, Markus Spoettl wrote:

On Jan 20, 2009, at 11:06 PM, Alex Mills wrote:
I have built a Javascript WYSIWYG editor. I want to build a WebKit based cocoa app with buttons that can call a function from the editor loaded in webkit. For example I want to have a button within the Cocoa interface that calls the Javascript function 'makeBold()' to make the selected text within the editor bold. If this is possible I then want to save the editor generated html to string so that I can store it within Core Data. I checked out the Apple Webkit programming guide but it doesn't provide much.


Have a look at "Using JavaScript From Objective-C" in the WebKit Objective-C Programming Guide:

<http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/JavaScriptFromObjC.html#//apple_ref/doc/uid/30001214 >

What it explains is how you can evaluate any JavaScript code from your app (which means calling functions too), you can also have JavaScript functions call back into your own Objective-C code.

Regards
Markus
--
__________________________________________
Markus Spoettl

_______________________________________________

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

_______________________________________________

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: 
 >Interaction with web javascript & cocoa (From: Alex Mills <email@hidden>)
 >Re: Interaction with web javascript & cocoa (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Re: Draw NSView over QTMovieView
  • Next by Date: Re: Draw NSView over QTMovieView
  • Previous by thread: Re: Interaction with web javascript & cocoa
  • Next by thread: Observing edits make to a table using bindings
  • Index(es):
    • Date
    • Thread