簡體   English   中英

window.print 在 webview 中不起作用。xamarin.android

[英]window.print is not working in webview. xamarin.android

我在 webview 的幫助下打開了一個 web 頁面。當我點擊其中的一個按鈕時;

var newWindow=window.open();
newWindow.document.body.innerHTML="<table>....</table>";
setTimeout(() => {
    newWindow.print();
    newWindow.close();
}, 1000);

交易正在進行中。 但不知何故,新屏幕沒有出現,打印屏幕也沒有出現。

和我的 xamarin.adroid 代碼;

 WebView web_view;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        SetContentView(Resource.Layout.activity_main);
        Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);

        web_view = FindViewById<WebView>(Resource.Id.webview);
        web_view.SetWebChromeClient(new ExtendWebChromeClient(this));
        web_view.SetWebViewClient(new WebViewClient());
        web_view.Settings.JavaScriptEnabled = true;
        web_view.Settings.AllowFileAccess = true;
        web_view.Settings.JavaScriptCanOpenWindowsAutomatically = true;
        web_view.Settings.SetSupportMultipleWindows(true);
        web_view.Settings.SetSupportZoom(true);
        web_view.Settings.BuiltInZoomControls = true;
        web_view.Settings.DomStorageEnabled = true;
        web_view.Settings.LoadWithOverviewMode = true;
        web_view.Settings.DisplayZoomControls = true;
        web_view.Settings.AllowContentAccess = true;
        web_view.Settings.DefaultTextEncodingName = "utf-8";
        web_view.Settings.SafeBrowsingEnabled = true;
        web_view.Settings.UseWideViewPort = true;
        web_view.SetWebViewClient(new HelloWebViewClient());
        web_view.LoadUrl("https://sample.com");
        web_view.Settings.SetPluginState(PluginState.On);
    }

我進入 chrome 並在chrome://inspect/#devices 的幫助下調試我的代碼。 我沒有收到任何錯誤。 我能做什么?

不能直接在android中使用window.print() function。 嘗試打印 web 查看選項,並通過網站的 html 按鈕使用 javascript 界面打印按鈕單擊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM