TroyBarlow1
TroyBarlow1
  • 发布:2019-02-20 11:05
  • 更新:2022-01-07 23:38
  • 阅读:2856

怎样实现: webview加载外部网页,网页中img标签加载本地图片

分类:HTML5+

实验过的解决方案:

1: var Webview = plus.android.importClass("android.webkit.WebView");
var WebSettings = plus.android.importClass("android.webkit.WebSettings");
var wv = plus.android.currentWebview();
var setting = plus.android.invoke(wv, "getSettings");

    setting.setAllowUniversalAccessFromFileURLs(true);  
    setting.setAllowFileAccess(true);  
    setting.setAllowFileAccessFromFileURLs(true);  
    setting.setAllowContentAccess(true);  
    setting.setJavaScriptEnabled(true)  

    plus.android.invoke(setting, "setAllowUniversalAccessFromFileURLs", true);   
    plus.android.invoke(setting, "setAllowFileAccess", true);  
    plus.android.invoke(setting, "setAllowFileAccessFromFileURLs", true);  
    plus.android.invoke(setting, "setAllowContentAccess", true);  
    plus.android.invoke(setting, "setJavaScriptEnabled", true);  

以上代码不能实现如题的需求,已亲自试验过;

2:离线打包,离线打包时重写 shouldInterceptRequest ,使webview失去同源策略限制,但目前此解决思路没有实现过;

还有没其他思路,请各位大神帮忙

2019-02-20 11:05 负责人:无 分享
已邀请:
3***@qq.com

3***@qq.com

let view=plus.webview.currentWebview();
view.overrideResourceRequest([{match:"file://.*",redirect:"_downloads/OrderImg/imageView/1540.jpg"}]);
这个方法可以 但是只能拦截后重定向固定的本地文件。不能动态修改

  • 3***@qq.com

    file 可以弄个其它自定名的


    2021-10-07 01:16

  • 3***@qq.com

    let view=plus.webview.currentWebview();

    view.overrideResourceRequest([{match:"local://.*",redirect:"_downloads/OrderImg/imageView/1540.jpg"}]);


    <image src="local://aa.jpg"> 这样能访问到本地APP中的对应文件 缺点不能动态修改


    2021-10-07 01:18

回梦無痕

回梦無痕 - 暂停服务

http://localhost:13131/_www/res/icon.png  
//其中“_www”字段可支持类型与相对路径URL一致

这样试下?

  • 2***@qq.com

    不行 ,我的做法是

    plus.zip.compressImage(

    {

    src:url,

    dst:name,

    quality:35,

    overwrite:true

    },function (event) {

    entryUrl=event.target;//存储本地路径

    plus.io.resolveLocalFileSystemURL(event.target,function (entry) {

    var temp= entry.toRemoteURL().replace(/file.*/,"")

    //

    temp=temp+name;

    // alert(temp)

    addImage(temp,event.target,imgUrlUpList.length)

    } )

    }

    )


    真机运行可以 ,云打包后不行 。


    2019-11-25 11:53

2***@qq.com

2***@qq.com

很急 怎么才能显示 列

小七哥

小七哥

请问怎么解决么?

该问题目前已经被锁定, 无法添加新回复