How to load files into webview in native script

后端 未结 1 1342
温柔的废话
温柔的废话 2021-01-16 09:53

I\'ve been trying to figure out a way to get a local webpage content to load and set the webview html content in native script. I\'ve successfully got it working on the sim

1条回答
  •  滥情空心
    2021-01-16 10:10

    Here is an example how to add WebView src from local file. In the example has been shown the both cases with nativescript-webview-interface plugin and without it. ~/ returns the path to your app folder.

    main-page.xml

    
      
          
          
      
    
    

    main-page.ts

    import { EventData } from 'data/observable';
    import { Page } from 'ui/page';
    import { HelloWorldModel } from './main-view-model';
    var webViewInterfaceModule = require("nativescript-webview-interface");
    import {WebView} from "ui/web-view";
    
    var oWebViewInterface;
    export function onLoaded(args: EventData) {
      let page = args.object;
      var webView:WebView = page.getViewById('WebViewId');
      oWebViewInterface = new webViewInterfaceModule.WebViewInterface(webView, '~/index.html');
      var SecondWebView:WebView = page.getViewById('WebViewId2');
      SecondWebView.src="~/secondpage.html"
      page.bindingContext = new HelloWorldModel();
    }
    

    0 讨论(0)
提交回复
热议问题