Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject js file in wpf webbrowser control in c#

Hi I am using WPF WebBrowser control on my xaml page. I have Html,Jquery,js, and css file in my html package. I have to load html page in web browser control with all jquery library. How can I inject this file? I am writing code like this:

page.xaml.cs

 void wb_Loaded(object sender, RoutedEventArgs e)
    {
        string htmlPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "keyboardWidget\\test.html");
        string html = File.ReadAllText(htmlPath.ToString());
        webBrowser.NavigateToString(html);

    }

this is page.xaml:

<WebBrowser x:Name="webBrowser"></WebBrowser>

I am getting error Like this.

enter image description here

Hi can anyone suggest what is the best way to inject js or jquery library. if it's not possible in wpf web browser control then what control I should use.

like image 605
Jitendra singh Avatar asked Aug 07 '15 12:08

Jitendra singh


1 Answers

I suspect the problem might not be that the JS script was not found by the WebBrowser control, but that the WPF WebBrowser control has compatibility issues with JSON.

Try including this script in your page and see if it resolves the problem: JSON2

Download the json2.js and include this in the HTML of your page:

<script  type="text/javascript" src="json2.js"></script>
like image 124
Glen Thomas Avatar answered Nov 18 '22 15:11

Glen Thomas