Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script is not working in WebView in UWP

I am using following web view in xaml.

<WebView x:Name="FBCommentsTest"></WebView>

And i am trying to embed HTML data to that web view in the following way in the c# end.

FBCommentsTest.NavigateToString("<html><head></head><body><div id=\"fb-root\"></div><div id=\"fb-root\"></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) return;js = d.createElement(s); js.id = id;js.src = \"http://connect.facebook.net/en_US/all.js#xfbml=1&appId=" + APP_KEY + "\";fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class=\"fb-comments\" data-href=\""
                + mExternalUrl + "\" data-width=\"500\"></div> </body></html>");

But, in the web view i am getting an empty screen not able to get the facebook comments view. How to enable the script in web view in uwp. Please help me. Thanks.

like image 311
Bhanuprakash Mankala Avatar asked Feb 01 '26 06:02

Bhanuprakash Mankala


1 Answers

But, in the web view i am getting an empty screen not able to get the facebook comments view. How to enable the script in web view in uwp.

The NavigateToStringmethod does not provide a way to generate or provide css, scripts, images, and fonts resources programmatically. You can refer to WebView.NavigateToString method.

You can transfer your string into HTML file, and use Navigate method to navigate to the HTML page. Just for example, create a HTMLPage file in the project and code for it, then in the c# code behind:

Uri uri = new Uri("ms-appx-web:///HTMLPage1.html");
FBCommentsTest.Navigate(uri);
like image 185
Grace Feng Avatar answered Feb 02 '26 18:02

Grace Feng