• 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: Getting WebView and JavaScript to communicate. MFC can do it.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting WebView and JavaScript to communicate. MFC can do it.


  • Subject: Re: Getting WebView and JavaScript to communicate. MFC can do it.
  • From: Daniel Jalkut <email@hidden>
  • Date: Wed, 11 Jan 2006 10:45:48 -0500


It's true that the connection has to be made from the Cocoa side, but once it's done, the JavaScript itself has access to the cocoa object. It works something like this:


[myScriptObject setValue:myCoolObject forKey:@"coolCocoaObject"];

Now from this point forward your javascript inside the webview can do something like this:

myCoolObject.DoCoolStuff();

It's a little more complicated for methods with arguments, because there is some automatic name changes to get around the problematic (?) colons in ObjC selectors.

Daniel

On Jan 11, 2006, at 6:23 AM, Theodore H. Smith wrote:


On 11 Jan 2006, at 06:45, Daniel Jalkut wrote:

Hi Theodore - I think what you want is the (relatively) recently added "WebScriptObject" functionality on WebView.

Search on "WebScriptObject" and if none of that makes sense try "WebScriptObject Dashboard" because Dashboard widgets use a very concrete example of setting Cocoa objects as WebScriptObject properties that can then be accessed from within the JavaScript context.

The gist is that you wait for your WebView to "have a web script object available," and then you can simply "setValue" on it to represent your Cocoa object in the JavaScript namespace with a specified name.

Daniel

Hi Daniel,

I'm not sure if I understand the docs correctly, but it seems that WebScriptObject only allows interaction from the opposite direction that I want. it allows Cocoa apps to get and set stuff into JavaScript.

I want JavaScript HTML pages to be able to get and set stuff into Cocoa. That is, at the WebView's event time, not any NSButton's event time.

For example, user clicks on a link in a HTML page. The link activates some JavaScript, the JavaScript grabs some info from my app. That's the opposite of what WebScriptObject gives.

WebScriptObject will allow my to click on an NSButton outside of my WebView (or some other thing which creates an event), the NSButton can ask the WebScriptObject to get some data from the JavaScripts. You see? Its the opposite direction.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
sweater.com


This email sent to email@hidden

_______________________________________________ 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
References: 
 >Getting WebView and JavaScript to communicate. MFC can do it. (From: "Theodore H. Smith" <email@hidden>)
 >Re: Getting WebView and JavaScript to communicate. MFC can do it. (From: Daniel Jalkut <email@hidden>)
 >Re: Getting WebView and JavaScript to communicate. MFC can do it. (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: Why do all subcell buttons highlite for custom cell in NSTableView?
  • Next by Date: Re: Cocoa control in carbon window
  • Previous by thread: Re: Getting WebView and JavaScript to communicate. MFC can do it.
  • Next by thread: Re: Getting WebView and JavaScript to communicate. MFC can do it.
  • Index(es):
    • Date
    • Thread