1

I am working on android WebView, consider the numbers listing 1-100 if I click 55 the page have to take to the landing page and have to scroll the number 55th paragraph automatically from there i may again scroll up or down, we have tried using JavaScript included on the web view to achieve this unfortunately it was not working and showing no errors

And the code as follows

String content ="
<script src='jquery-3.2.1.min.js' type='text/javascript'></script>
<script src='jquery-ui-1.12.1/jquery-ui.min.js' type='text/javascript'></script>
<script>  
        function scrollToElement(id) {
            var elem = document.getElementById(id);
            var x = 0;
            var y = 0;

            while (elem != null) {
                x += elem.offsetLeft;
                y += elem.offsetTop;
                elem = elem.offsetParent;
            }
            window.scrollTo(x, y);
        }
        </script>";

       content += "<div id="+i+">";
         i++;
         content += cursor.getString(cursor.getColumnIndex(VERSE_CONTENT));
         content+="</div>";

i have included the js files on assets folder, any suggestions will be really appreciated.

2
  • What is error's ? Commented Jan 29, 2018 at 10:31
  • unfortunately i didn't get any errors Commented Jan 29, 2018 at 12:24

1 Answer 1

1

You must enable javascript prior to use it as stated into documentation

WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

After this you should get at least some errors for the running code.

Sign up to request clarification or add additional context in comments.

1 Comment

you must get at least some error... can you provide more info??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.