Load content script "Playbuzz" in a WebView

2

I try to upload content from a "playbuzz" script within WebView , I found a way to do it, which is loading the script in a web page:

String urlPlayBuzz = "http://www.jorgesys.com/playbuzzcontent.html";
webview.loadUrl(urlPlayBuzz);

But my requirement is to only load the script and display the content:

String script = "<center style=\"width:100%;\"><script> (function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src='//embed.playbuzz.com/sdk.js' ;fjs.parentNode.insertBefore(js,fjs);}(document, 'script' , 'playbuzz-sdk' ));</script><div class=\"playbuzz\" data-id=\"9ed89fec-22cb-441e-b2a3-69b3bd1e6953\" data-show-info=\"false\" data-show-share=\"false\" style=\"width:100%;height:56.25vw\"></div></center>";

I tried this option:

    webview.loadUrl(script);

and also:

    webview.loadData(script,"text/html","UTF-8");

both unsuccessfully, just show me the WebView blank:

It is important to comment that if I complete the relative path that the script of the file src='//embed.playbuzz.com/sdk.js' has, it does not work completely.

How could I load a "playbuzz" script correctly into a WebView?

    
asked by Elenasys 13.12.2017 в 04:42
source

1 answer

1

I found that unlike other scripts (for example twitter or instagram) the embedded code has defined relative paths, for example:

js.src='//embed.playbuzz.com/sdk.js'

Therefore in this case by means of the method:

  

loadDataWithBaseURL () Load the data given in this WebView,   using baseUrl as the base URL for the content. The base URL is used   both to resolve relative URLs and to apply the same policy   of JavaScript origin. The historyUrl is used for the input of the   history.

you can define the base path content,

webview.loadDataWithBaseURL("https://embed.playbuzz.com.com", url, "text/html", "UTF-8", null);

This way you can load the content for embedded code that contains scripts with relative paths.

    
answered by 21.02.2018 / 21:36
source