Skip to content

WebView plugin for Zebble for Xamarin to show HTML pages and content.

Notifications You must be signed in to change notification settings

Geeksltd/Zebble.WebView

Repository files navigation

Zebble.WebView

logo

A Zebble plugin that allow you to show web pages in your application.

NuGet

A WebView component (sub-class of View) allows you to render a piece of Html or a whole URL in an embedded browser component.


Setup


Api Usage

To show an external URL, use:

<WebView Url="http://www.Google.com" />

To show some html directly, use:

<WebView Html="@GetHtml...()" />

The value of HTML can be a full html page (wrapped in a ... tag), or a partial html piece such as "<b>something</b>".

In the above example GetHtml() is a method in the code behind. Of course the data can come from the database, your domain objects, etc.

To show a html file from your Resources folder, use:

<WebView Url="MyPages/SomePage.html" />

The above example assumes you have a file named SomePage.html under App.UI\Resources\MyPages folder.

Javascript, Image and CSS Files In the HTML page, you can reference Javascript, Image or CSS files in your Resources folder. You can also reference web-hosted resources by specifying the full url. For example:

...
<script type="text/javascript" src="MyPages/MyScript.js"></script>
<script type="text/javascript" src="http://mywebsite.com/MyScript.js"></script>
...
<img src="Images/Icons/Hello.png">

Running Javascript from Zebble

The EvaluateJavascript() method allows you to run some Javascript code on the rendered page, and then get the value of its evaluation back.

MyWebView.EvaluateJavascript("$('.some-object').attr('value')");
Important Tips

When generating a full page html, remember to set the viewport meta tag, otherwise the content will be rendered at the top left corner in UWP.

<head>
    <meta name="viewport" content="width=device-width", initial-scale="1">
</head>

If using a local html file, it should be a valid xhtml. For example all tags should be closed and lowercase. UWP does not support loading html content from local storage. However, Zebble solves that limitation. This is how it works: It reads the HTML file and parses the html. It then looks for <script> and <link css> tags which reference a local file. It will then load those files and copies their content as embedded code inside the html page. It will then load the combined html on the native device browser component.

Value:

The Value property determines the HTML content of current page.

Properties

Property Type Android iOS Windows
Url string x x x
Html string x x x
Value object x x x
MergeExternalResources bool x x x

Events

Event Type Android iOS Windows
BrowserNavigated AsyncEvent x x x
BrowserNavigating AsyncEvent<NavigatingEventArgs> x x x
LoadingError AsyncEvent<string> x x x
LoadFinished AsyncEvent x x x
SourceChanged AsyncEvent x x x

Methods

Method Return Type Parameters Android iOS Windows
SetHtml Task value -> string x x x
SetUrl Task value -> string x x x
EvaluateJavaScript void script-> string x x x
EvaluateJavaScriptFunction void function -> string, args-> string[] x x x
GetExecutableHtml string - x x x

About

WebView plugin for Zebble for Xamarin to show HTML pages and content.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages