Communicating Javascript tp Code

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Communicating Javascript tp Code

Postby MAHE202 » Wed Sep 11, 2013 3:56 am

In IE, We have an option to execute a C# method from Java script as below. By making them as a comvisible class..

http://justyouraveragegeek.com/blog/ind ... baseclass/

I have to implement similar things with chrome.. Javascript calling C# code. Pls provide some hint to start..

Thanks.
MAHE202
Techie
 
Posts: 10
Joined: Wed Aug 28, 2013 6:05 am

Re: Communicating Javascript tp Code

Postby fddima » Wed Sep 11, 2013 5:16 am

Hi.

It is discussed many times. There exists two common ways:

1) By using V8 binding CEF features. It is allow expose some objects into V8 environment. I.e. provide something like JSBinding feature from CefGlue1. But, note, that V8 lives in renderer process, so in this case you will need additional IPC to main (browser) process.

2) By using XHR - IPC mechanism between JS and main process already exists: on JS side use XHR (XMLHttpRequest) to perform requests to your's code, and at the main process you can handle this requests with custom scheme handlers.

I'm always recommend second way, 'cause it is really more simpler, than first, and it is web standards based.

PS: At this moment Xilium.CefGlue did not contain any automation for any of ways described above (JSBinding feature).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Communicating Javascript tp Code

Postby MAHE202 » Wed Sep 11, 2013 7:56 am

Ok. After going through the forum previous post.. I've got some idea about V8.. but to start from JS.. i need your help. I mean, let say.
1) Have a button in html, on click of Javascript I need to invoke C#
2) In C#, I think V8 would get the call from UI ?
3) In C#, I 'm returning a "Person object" which has got name,age, etc.. to be returned to JS
4) In JS, I'm trying to display

JS-> C# -> do some process like return my request object -> C#(return) -> JS

Could you pls provice some JS interfacing code with C#? Sorry about it.
MAHE202
Techie
 
Posts: 10
Joined: Wed Aug 28, 2013 6:05 am

Re: Communicating Javascript tp Code

Postby fddima » Wed Sep 11, 2013 9:07 am

Why you did not want use XHR?
Javascript on button click sent usual http request, for example via jQuery.ajax. Main process handle it. Very simple scheme handler source exist in Demo application (in CefGlue.Demo assembly).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 22 guests