Pattatharasu Nataraj
Pattatharasu Nataraj

Reputation: 248

using javascript on android webview java

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.

Upvotes: 1

Views: 192

Answers (1)

Jordi Castilla
Jordi Castilla

Reputation: 26961

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.

Upvotes: 1

Related Questions