html5 - How can i render html website in nativescript application? -
how can render html and/or non local website nativescript
app? cant find way start or manipulate browser instance.
the documentation quite bit, here 2 examples:
example url
this example create new page webview on , navigate page. url may local (html file on phone) or remote (http://...)
var framemodule = require('ui/frame'); var pagemodule = require('ui/page'); var webviewmodule = require("ui/web-view"); var factoryfunc = function () { var webview = new webviewmodule.webview(); webview.url = 'http://www.example.com'; var page = new pagemodule.page(); page.content = webview; return page; }; framemodule.topmost().navigate(factoryfunc);
example of loading local data webview
an example of have view (.xml
) , and corresponding .js
file , feed string containing html displayed.
where .xml
is:
<page xmlns="http://www.nativescript.org/tns.xsd" loaded="loaded"> <webview id="mywebview" /> </page>
and .js
:
exports.loaded = function(args) { var page = args.object; var webview = page.getviewbyid('mywebview'); var application = require('application'); var html = '<html><body><h1>i can haz webview?</h1></body><html>'; if (application.ios) { webview.ios.loadhtmlstringbaseurl(html, null); } else if (application.android) { webview.android.loaddata(html, 'text/html', null); } };
Comments
Post a Comment