javascript社交共享不适用于android webview

时间:2018-11-29 13:00:49

标签: javascript android android-webview

我有一个网页,该网页具有javascript社交共享,并且我使用android webview来显示此页面,问题是当我按whatapp共享或Messenger时,它不起作用,但与Facebook共享很好地配合。 请注意,我尝试在移动浏览器上打开网页,所有共享按钮均正常运行 这是我的JavaScript代码:

<script type='text/javascript' src='//platform-api.sharethis.com/js/sharethis.js#property=5b94a08891dd5500119063ef&product=social-analytics' async='async'></script>

这是我的webview代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mwebView = findViewById(R.id.webView);
    WebSettings webSettings = mwebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mwebView.loadUrl(" https://www.talabito.com");


    mwebView.setWebChromeClient(new WebChromeClient());


    //improve webview
    mwebView.setWebViewClient(new myWebViewClient());
    //make app open from cache when the internet is not available
    mwebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
    mwebView.getSettings().setAppCacheEnabled(true);//enable the Application Caches API
    mwebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webSettings.setDomStorageEnabled(true);//enable the DOM storage AP
    //controlling the layout of html
    webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    webSettings.setUseWideViewPort(true);
    webSettings.setSavePassword(true);// to save password
    webSettings.setSaveFormData(true);// save form data.
    webSettings.setEnableSmoothTransition(true);
    CookieManager.getInstance().setAcceptCookie(true);
    if (Build.VERSION.SDK_INT >= 21) {
        mwebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        CookieManager.getInstance().setAcceptThirdPartyCookies(mwebView, true);}}



 private class setWebChromeClient extends WebChromeClient  {
    @Override
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        //Required functionality here
        return super.onJsAlert(view, url, message, result);
    }}

 private class setWebChromeClient extends WebChromeClient  {
    @Override
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        //Required functionality here
        return super.onJsAlert(view, url, message, result);
    }}

0 个答案:

没有答案