【问题标题】:Change schema protocol to http:// in WebView Android在 WebView Android 中将架构协议更改为 http://
【发布时间】:2014-02-27 10:51:24
【问题描述】:

我的 Android 应用程序中有一个 WebView,我使用库 jsoup 从 html 页面中提取“div”。在这个“div”中,我有一些执行的 javascript 脚本,但问题是脚本的 url:

'//' + disqus_shortname + '.' + 'disqus.com' + '/embed.js?pname=wordpress&pver=2.74

我在“//”之前没有任何协议,所以脚本没有加载,我想在脚本的url之前添加“http”协议。有什么想法吗?

谢谢大家,

PS : 这是我的第一篇文章 :)

【问题讨论】:

    标签: javascript android http webview protocols


    【解决方案1】:

    使用WebView.loadDataWithBaseURL() 函数指定基本URL。实际上,“//”是有效的,意思是“使用与基本 URL 相同的协议,但具有给定的域”。通过使用“loadDataWithBaseURL”而不是其他加载方法,WebView 应该能够使用您指定的基本 URL 解决此问题。

    【讨论】:

    • 谢谢你的快速解答。其实这个功能我已经试过了,但是不知道baseUrl里面要放什么。有我的函数 loadDataWithBaseURL() : webDisqus.loadDataWithBaseURL("http:", result, "text/html", "UTF-8", null);
    • 这取决于页面“结果”代表什么。如果有结果的在线表示,您应该使用该 URL。
    【解决方案2】:

    寻找在 WebView Android 中集成 Disqus 的解决方案:

    return "<html><head></head><body><div id='disqus_thread'></div></body>"
                + "<script type='text/javascript'>"
                + "var disqus_identifier = '"
                + idPost
                + "';"
                + "var disqus_shortname = '"
                + shortName
                + "';"
                + " (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;"
                + "dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';"
                + "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();"
                + "</script>";
    

    希望对您有所帮助:)

    【讨论】:

      猜你喜欢
      • 2015-02-14
      • 2018-10-17
      • 2013-09-13
      • 1970-01-01
      • 2021-12-14
      • 2012-04-05
      • 2023-03-19
      • 1970-01-01
      • 2019-02-04
      相关资源
      最近更新 更多