2

I use loadUrl function to call a JavaScript function inside my webview:

webview.loadUrl("javascript:(function(){var txt = window.getSelection();window.name= txt;window.cpjs.sendToAndroid(window.name);window.cpjs.sendTest(5);})()");

but how can I call more than one JavaScript function inside loadUrl?

1 Answer 1

3

You can do this in a similar way to which you have above but define the functions in an anonymous parent function, then self-execute:

javascript:(function(){
    function firstFunction(){
        alert('First function called');
    }
    function secondFunction(){
       alert('Second function called');
    }

    firstFunction();
    secondFunction();
})()
Sign up to request clarification or add additional context in comments.

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.