FrankFabregat2
FrankFabregat2

Reputation: 305

Execute JavaScript function from Android WebView

I have been trying to call a JavaScript function called showMenu(); from an Android WebView. However, I have tried what many articles on StackOverflow say about doing

webview.loadURL("javascript:showMenu()"); 

and it shows this in the console:

I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: showMenu is not defined", source: https://url.com/index.php (1).

I am new at Android and I am pretty sure it is a simple fix, but I could not find it anywhere. How can I do this?

EDIT: JavaScript is enabled

Upvotes: 1

Views: 1479

Answers (1)

FrankFabregat2
FrankFabregat2

Reputation: 305

I removed the function from the <script> tags, and put it in a .js file using 'use strict'; and worked :)

Upvotes: 0

Related Questions