【问题标题】:How to load external webpage in webview? I need to load the advertise when clicked button of webview如何在 webview 中加载外部网页?单击 webview 的按钮时,我需要加载广告
【发布时间】:2016-02-15 06:08:17
【问题描述】:

点击网页按钮时需要从webview打开外部网页!我通过使用WebChromeClient 和覆盖onJsConfirm() 函数解决了如何打开外部链接的问题。现在我需要在相同的 webview 中显示较小尺寸的外部链接,并且我可以选择取消相同 WebView 活动中的外部网页(自定义广告页面)!需要帮助。

final class MyWebChromeClient extends WebChromeClient {

    @Override
    public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
        new AlertDialog.Builder(getContext())
                .setTitle("App Titler")
                .setMessage(message)
                .setPositiveButton(android.R.string.ok,
                                  new DialogInterface.OnClickListener()
                        {
                            public void onClick(DialogInterface dialog, int which)
                            {
                                result.confirm();
                            }
                        })
                .setNegativeButton(android.R.string.cancel,
                        new DialogInterface.OnClickListener()
                        {
                            public void onClick(DialogInterface dialog, int which)
                            {
                                result.cancel();
                            }
                        })
                .create()
                .show();

        return true;
    }

}

【问题讨论】:

  • 您可以在WebView中编辑您正在加载的网页吗?
  • 对不起!我没有明白你在说什么“编辑”!我可以使用网页的所有功能!但是外部页面通过占用移动设备的所有空间来打开!当我点击返回时,网页没有打开!!
  • 您的意思是外部链接会在您的手机浏览器中打开吗?并且您想在您的应用程序中打开链接?

标签: android webview


【解决方案1】:
    WebView webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(pass your url here);

希望这会有所帮助!

【讨论】:

  • 我用过!它只执行主网页!我需要使它适用于在 webview 中单击某些按钮时将加载的另一个网页
猜你喜欢
  • 2011-11-10
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2019-04-20
  • 1970-01-01
  • 2013-01-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多