0

I am new in xamarin and c# forms platform. I make a simple webview application. and my main page is

namespace jsinjection
{
    public class WebviewPage : ContentPage
    {

        public WebviewPage ()
        {
            Content = new WebView {

                Source = "https://www.google.com.tr/",
                HeightRequest = 1000,
                WidthRequest = 1000
            };
        }
    }
}

I want to do javascript injection to that webview according to platform specific data. But I dont know how to get this webview outside of its class. And which part of the project should I do injection.

2 Answers 2

2

See if you can use the below code:

WebView wv = new WebView();
wv.EvaluateJavascript ("document.body.innerHTML");

or

wv.InvokeScriptAsync("eval", new string[] { "document.body.innerHTML" });

See also: Xamarin: How to get HTML from page in WebView?

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look to Xamarin.Forms.HtmlWebViewSource

And here is an example:

// Get html content of your page.. 
// It could contain javascript code or references to files in the assets (example bellow).
string htmlText = MyItem.Article.ToString();

var browser = new WebView ();
var html = new HtmlWebViewSource {
  Html = htmlText
};

// Set your HTML content to implemented WebView
browser.Source = html;

Or using Xamarin.Forms.UrlWebViewSource

// Just use local URL for your HTML file that stores inside your application content.
browser.Source = new UrlWebViewSource {Url = "Content/index.html"};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.