简体   繁体   English

在WebView Android中将架构协议更改为http://

[英]Change schema protocol to http:// in WebView Android

I have a WebView in my Android App, I extract with the library jsoup a "div" from an html page. 我的Android应用程序中有一个WebView,我使用库jsoup从html页面中提取了一个“ div”。 In this "div", I have some javascript script that execute, but the problem is the url of the script : 在这个“ div”中,我有一些可执行的javascript脚本,但是问题是脚本的URL:

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

I don't have any protocol before the "//", so the script doesn't load, I want to add the "http" protocol before the url of the script. 我在“ //”之前没有任何协议,因此脚本不会加载,我想在脚本的网址之前添加“ http”协议。 Any ideas? 有任何想法吗?

Thank you everybody, 谢谢大家,

PS : it's my first Post :) PS:这是我的第一篇文章:)

Use the WebView.loadDataWithBaseURL() function to specify a base URL. 使用WebView.loadDataWithBaseURL()函数来指定基本URL。 The "//" is, in fact, valid and means to "use the same protocol as the base URL but with the given domain." “ //”实际上是有效的,并且意味着“使用与基本URL相同的协议,但具有给定的域”。 By using "loadDataWithBaseURL" instead of the other load methods, the WebView should be able to resolve this with the base URL you specify. 通过使用“ loadDataWithBaseURL”代替其他加载方法,WebView应该能够使用您指定的基本URL来解决此问题。

Find the solution to integrate Disqus in WebView Android : 查找解决方案以将Disqus集成到WebView Android中:

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>";

Hope that could be helpful :) 希望对您有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM