1

I want to add my javascript to the remote website.

I tried to use the method onPageFinished but it only get the website before the script run. The website has to get all data from server and I have to wait until it finished so I can add js to the generated element.

All elements I want to use have to wait until the script generate them

How can I know when the website has fully rendered? (ran all scripts and has all generated html)

EDIT

I can get the generated html but it can't help anything ( this )

I also tried many solutions but they didn't work (this and this)

Here my sample code

webPreviewDocument.setWebViewClient(new WebViewClient(){
@Override  
public void onPageFinished(WebView view, String url) {
    webPreviewDocument.loadUrl("javascript:alert('Example');"); // just example
}
});
WebSettings webSettings = webPreviewDocument.getSettings();
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
webSettings.setLoadWithOverviewMode(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webPreviewDocument.loadUrl(mMaterialPreview.getPreviewUrl());

When the page is loading

when onPageFinished called, the page is loading preview content, I have to wait few seconds and then to all the content loaded. I also tried to use sleep and wait for both js and java but it doesn't work

Minh Luân
  • 39
  • 6

1 Answers1

0

You can do something like this in your JS file:

var init = function () {
    //here you write your functions that need to be excuted by example:
    $('.checkbox').on('change', checkCheckbox);
};
$(document).ready(init());

The function init() can only be excuted when your document has loaded. This function is also written in Jquery. I don't know if you use that or know that. If you have any more questions just ask

Steven
  • 1,404
  • 2
  • 16
  • 39
  • I have tried that but it won't work. Because in Android, when I load a page, it always call onPageReturn immediately although the page have to load the preview content. For example: when you click to open an image in Google Photo, it have to load the preview content for few seconds before show it up. – Minh Luân Aug 22 '17 at 09:23
  • Can you show me your android code? Also can you show me how you load that content? – Steven Aug 22 '17 at 09:24