2

I have a function JavaScript that i want to inject in a Html, with the WebView. I can inject small pieces of JavaScript code with loadUrl("javascript:..." but when i try to insert the code does not work.

Code:

<script type="text/javascript" language="javascript">
    var i = 0;

    function timer() {
        tot = document.links.length;
        if (i < tot+1) {
        document.getElementById('link'+i).focus();
            i++;
            setTimeout("timer()", 1000);
        }
    if(i==tot)
        i=0;
    }
    setTimeout("timer()", 1000);

</script>

2 Answers 2

4

Its actually simple, once your webview loading is finshed onPageFinished() , call webview.loadUrl(“javascript:your-javascriptcode-here”) take a look here

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

Comments

0

Maybe something like:

loadUrl("javascript:(function(){" +
  "var i = 0;" +
  "function timer() {" +
  "    tot = document.links.length;" +
  "    if (i < tot+1) {" +
  "    document.getElementById('link'+i).focus();" +
  "        i++;" +
  "        setTimeout('timer()', 1000);" +
  "    }" +
  "if(i==tot)" +
  "    i=0;" +
  "}" +
  "setTimeout('timer()', 1000);" +
"})()");

Comments

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.