Loading jQuery in CefSharp webView_LoadCompleted - not working !!!

1,087 views
Skip to first unread message

Tony Mullins

unread,
Jan 28, 2014, 4:09:25 AM1/28/14
to cefs...@googlegroups.com
Hi,

I have downloaded CefSharp from GitHub and using version 1.25.4.0 in my custom WinForm's application.
Problem is if I inject simple JavaScript code its working but jQuery code is not working.
In my webView_LoadCompleted event I am doing this

if (!javascriptLoaded)
            {
              
               string jsfunction = File.ReadAllText(@"selector.js");
            
                 webView.ExecuteScript(jsfunction);
                //webView.EvaluateScript(jsfunction);
                javascriptLoaded = true;
                MessageBox.Show("Javascript has been injected ");
            }

and my seelctor.js file is

var jq = document.createElement('script');
jq.src = "http://code.jquery.com/jquery-latest.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();

$(document).click(function (e) {alert($(e.target).text());});

I have tried both ExecuteScript and EvaluateScript , both are not working !!!!
Could any one plz help here on what I am doing wrong here ???

Thanks,
Tony

Per Lundberg

unread,
Jan 28, 2014, 6:00:11 AM1/28/14
to cefs...@googlegroups.com
Hi Tony,

"Not working" is not really a very helpful error description unfortunately. You need to provide much more details. What happens, do you get an error message of some sort etc? I strongly suggest opening up the Developer Tools (if you have them available), they're incredibly useful whenever you are doing more or less any kind of JavaScript-related fiddling around. Check the code in the WPF example for how to open it. (Only CefSharp1 at the moment unfortunately...)

Best regards,
Per

Tony Mullins

unread,
Jan 28, 2014, 10:01:49 AM1/28/14
to cefs...@googlegroups.com
Hi Per,

What I meant from 'Not Working' was jQuery related functionality is not working wheras regular JavaScript is working.
But after doing lil tweaking to jQuery loading script , I managed to get it work. Now I am loading into body instead of head and using 'jQuery' instead of '$'.

var script = document.createElement('script');
script.src='http://code.jquery.com/jquery-latest.min.js';
document.body.appendChild(script);
jQuery.noConflict();

But Per, can u plz confirm 'webView_LoadCompleted' is right (appropriate)  event to inject custom JavaScript ?

Thanks,
Tony

Per Lundberg

unread,
Jan 30, 2014, 4:36:18 PM1/30/14
to cefs...@googlegroups.com
To be honest, "I don't know". I've never really had to do any of these "inject custom JavaScript" things, yet. :) Those of you who have tried it, please share your experiences with Tony.

Best regards,
Per
Reply all
Reply to author
Forward
0 new messages