简体   繁体   English

Xamarin Android Webview:不允许加载本地资源“file:///android_asset/*.css”来源:(1)?

[英]Xamarin Android Webview: Not allowed to load local resource “file:///android_asset/*.css” source: (1)?

I have a small CSS file I use with JavaScript to override the CSS on a website loaded in a WebView. 我有一个小的CSS文件,我用JavaScript来覆盖WebView中加载的网站上的CSS。 I would like to load it locally instead of need to access it online. 我想在本地加载它而不需要在线访问它。 I have gotten the JavaScript to work perfectly when the file is uploaded to a temporary filehost, so it works fine, but something regarding permissions won't let me use it as an asset. 当文件上传到临时文件主机时,我已经使JavaScript完美地工作,所以它工作正常,但有关权限的东西不会让我将它用作资产。

I've tried setting permissions, changing the WebView's settings to allow MixedContentMode always, tried using LoadData, etc, but it always throws the "Not allowed" issue. 我已经尝试设置权限,更改WebView的设置以允许总是使用MixedContentMode,尝试使用LoadData等,但它总是抛出“不允许”的问题。 The asset has the AndroidAsset build action. 该资产具有AndroidAsset构建操作。

string jsToInject = "javascript: var link=document.createElement('link');link.href='file:///android_asset/newsOverride.css';link.type ='text/css'; link.rel ='stylesheet';document.getElementsByTagName('head')[0].appendChild(link);";

view.LoadUrl(jsToInject);

When the link.href field is set to the file hosted on the web somewhere, it loads the CSS as expected. 当link.href字段设置为某处托管在Web上的文件时,它会按预期加载CSS。 But when it's selected as an asset it simply throws I/chromium(11626): [INFO:CONSOLE(1)] "Not allowed to load local resource: file:///android_asset/newsOverride.css", source: (1) 但当它被选为资产时,它只会抛出I/chromium(11626): [INFO:CONSOLE(1)] "Not allowed to load local resource: file:///android_asset/newsOverride.css", source: (1)

All I've been able to find on the error is with Xamarin Forms, not Xamarin Android, any help is appreciated. 所有我能找到的错误是Xamarin Forms,而不是Xamarin Android,任何帮助表示赞赏。

This issue should implementing the WebViewClient with a shouldInterceptRequest override like this thread. 这个问题应该像这个线程一样使用shouldInterceptRequest覆盖来实现WebViewClient。 Kitkat kills: Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png Kitkat杀死:不允许加载本地资源:file:///android_asset/webkit/android-weberror.png

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android不允许加载本地资源:file:/// android_asset - android Not allowed to load local resource:file:///android_asset 不允许加载本地资源:file:/// android_asset phonegap - Not allowed to load local resource:file:///android_asset phonegap Kitkat 杀死:不允许加载本地资源:file:///android_asset/webkit/android-weberror.png - Kitkat kills: Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png “不允许加载本地资源:file:///android_asset/webkit/android-weberror.png”) - “Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png”) android上的phonegap说:不允许加载本地资源:file:///android_asset/www/app/fb.js - phonegap on android says: Not allowed to load local resource: file:///android_asset/www/app/fb.js 不允许加载本地资源:file:///android_asset/... with Crosswalk 16+ - Not allowed to load local resource: file:///android_asset/... with Crosswalk 16+ Xamarin-文件:/// android_asset - Xamarin - file:///android_asset 加载webView.loadUrl(“ file:///android_asset/test.html”); 模拟器无法加载手机 - load webView.loadUrl(“file:///android_asset/test.html”); to emulator not load mobile Android WebView不允许加载本地视频文件 - Android WebView not allowed to load local video file android在webview中加载本地(在Asset / Res / External Storage中)pdf文件 - android load local(in Asset/Res/External Storage) pdf file in webview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM