Webview android target =' _blank'

时间:2017-07-11 12:19:18

标签: android html webview android-webview

我在Android Studio中构建了一个在Webview中显示页面的应用程序,但我似乎无法通过webview打开带有target =' _blank'在同一webview中。 可以这样做吗?

目前我有这个。现在,当我点击带有target =' _blank'的链接时,没有任何反应。 如果我更改了我的onCreateWindow,我会在外部浏览器中打开该链接,但我不希望发生这种情况。

我已经尝试使用谷歌搜索但无法找到解决方案。

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

    myWebView = (WebView) findViewById(R.id.myWebView);
    myWebView.loadUrl("http://test.dk");
    myWebView.setWebViewClient(new MyWebViewClient());
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSupportMultipleWindows(true);

    myWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, android.os.Message resultMsg)
        {

            WebView.HitTestResult result = view.getHitTestResult();
            String data = result.getExtra();
            //Context context = view.getContext();
            //Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
            //context.startActivity(browserIntent); // opens in external browser 
            myWebView.loadUrl(data); //don't work!
            return false;
        }
    });

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (myWebView.canGoBack()) {
                    myWebView.goBack();
                } else {
                    finish();
                }
                return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

// Use When the user clicks a link from a web page in your WebView
private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

       return  false;
    }
}

1 个答案:

答案 0 :(得分:0)

这对我有用。试试这个

else if(@Catcount > 2 )
    BEGIN
        declare @firstComma INT = (select CHARINDEX(',',@parm))
        Declare @secondComma INT = (select CHARINDEX(',', SUBSTRING(@parm, @firstComma+1, LEN(@parm))) + @firstComma)
        select @str = SUBSTRING(@parm,1, @secondComma-1) + ' and ' + CAST(@Catcount - 2 AS NVARCHAR(10)) + ' other catgeroris you follow.'
    END

创建私人课程

{{1}}