单击在WebView中不起作用

Ish*_*mar 8 javascript php android webview

我的Android应用程序中有一个webview.
我已经加载了网址:https://imsnsit.org/imsnsit/notifications.php
有各种通知的链接.单击它们时,我的WebView无效.它正致力于其他一切 - Chrome(Android),Chrome(桌面).链接很好.有一点我注意到通知有PHP文件的href.只是导航到该链接不起作用.我得到无效的操作.此外,链接不是静态的,每次刷新页面时它们都会更改(只有plum_url.php的参数).
我已经在使用这些功能了.什么都没有帮助.
webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setDomStorageEnabled(true);

meg*_*ind 5

我检查了你的链接,所有链接都打开了一个pdf文件,这在android web视图中是不受支持的.你可以在google docs中打开这样的链接,也可以在你的设备中打开一些应用程序.实现shouldOverrideUrlLoading像这样的东西.

 @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if ( urlIsPDF(url)){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(url), "application/pdf");
        try{
            view.getContext().startActivity(intent);
        } catch (ActivityNotFoundException e) {
            //user does not have a pdf viewer installed
        }
    } else {
        webview.loadUrl(url);
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)


小智 3

你可以像这样在 webview 中打开新窗口

WebView webviewContact=(WebView)findViewById(R.id.webviewcontact);  

webviewContact.loadUrl("https://imsnsit.org/imsnsit/notifications.php");

webviewContact.clearCache(true);

webviewContact.clearHistory();
//webviewContact.getSettings().setDomStorageEnabled(true);
//webviewContact.getSettings().setSupportMultipleWindows(true);
webviewContact.getSettings().setJavaScriptEnabled(true);        webviewContact.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webviewContact.setWebViewClient(new WebViewClient(){
/*For open new window in webview*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {                                    Toast.makeText(getApplicationContext(),url,Toast.LENGTH_SHORT).show();
                view.loadUrl(url);
                return false;
            }  
        });
Run Code Online (Sandbox Code Playgroud)