1

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

mplungjan
  • 134,906
  • 25
  • 152
  • 209
  • This isn't java question – Ravi Jan 28 '18 at 06:43
  • Make sure Javascript execution is enabled. or you can do so by `webView.getSettings().setJavaScriptEnabled(true);`. And make sure `showMenu()` is valid function, i suggest you try calling the same method on Google Chrome Insect window's console. – Sivakumar S Jan 28 '18 at 06:50
  • @SivakumarS I got that it is not defined. I currently have it set like `` – FrankFabregat2 Jan 28 '18 at 06:59
  • For Kotlin this might help : https://stackoverflow.com/a/54386184/6247186 – Hamed Jaliliani Jan 27 '19 at 08:03

1 Answers1

0

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