Simple Javascript call to c# using cefglue

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

Moderator: fddima

Simple Javascript call to c# using cefglue

Postby sravan19986 » Wed Sep 23, 2015 1:31 am

Hello every one,

i have written a simple html file which has javascript code and trying to call C# using CEF Glue

i have resgistered the scheme handler factory in my c# code as follows

CefRuntime.RegisterSchemeHandlerFactory("http", "portalCEF", new xyzSchemeHandlerFactory());

public class xyzSchemeHandlerFactory : CefSchemeHandlerFactory
{
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
{
return new xyzSchemeHandler();
}
}
public class xyzSchemeHandler : CefResourceHandler
{
protected override bool CanGetCookie(CefCookie cookie)
{
return false;
}

protected override bool CanSetCookie(CefCookie cookie)
{
return false;
//throw new NotImplementedException();
}

protected override void Cancel()
{
}

protected override void GetResponseHeaders(CefResponse response, out long responseLength, out string redirectUrl)
{
responseLength = -1; redirectUrl = null;
}

protected override bool ProcessRequest(CefRequest request, CefCallback callback)
{
return true;
}

protected override bool ReadResponse(System.IO.Stream response, int bytesToRead, out int bytesRead, CefCallback callback)
{
bytesRead = 0; return false;
}
}

Here is my Javascript code:
<script type="text/javascript">
function ShowWinFormsMessage(obj) {
alert("Hi")
$.ajax({
type: "POST",
url: "http://portalCEF",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
},
failure: function (response) {
alert(response.d);
}
});}
Note : Am calling ShowWinFormsMessage from c# code and the control is coming here but when i try to send some thing to C# from JS it is not happening.

Now am able to see the html page on browser, when i perform some action on html page i need to call my c# method using javascript.
can any one of you guys help me to write a simple javascript file to communicate with c#
sravan19986
Techie
 
Posts: 11
Joined: Fri Aug 28, 2015 4:52 am

Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 15 guests