<!doctype html>
<head>
<title>WebView Javascript Processor</title>
</head>
<body onload="processJavascript();">
<b>This page includes a javascript function that reverses text.</b>
<p>The javascript function incorporates a special App Inventor feature called <i>window.AppInventor.getWebViewString()</i>, which allows App Inventor apps to communicate with the WebViewer component's internal processing of javascript.
<p>This simple example shows how to use the <i>window.AppInventor.getWebViewString()</i> function to pass data to and from the WebViewer component, and thereby an App Inventor app.
<script>
var result = new Date().toString();
var appInventorInput = window.AppInventor.getWebViewString();
function processJavascript() {
if (appInventorInput.length > 0) {
document.write( "WebView InputString received FROM app:" + appInventorInput );
result = appInventorInput.split("").reverse().join("");
document.write( "<p/>WebView InputString sending BACK TO app:<br/>" +
result );
} else {
document.write( "No WebView InputString set by app at: <br/>" + result );
}
window.AppInventor.setWebViewString( result );
}
</script>
</body>
</html>
I tried looking through the forums and while I have found threads with this issue, they always point back to the localhost solution or put the HTML file in an actual server so I don't have to access it locally.
I guess my question is what am I doing wrong and what is the path to these Media files:
Try with the attached simpler html file in your assets. Does this display in your webviewer?
(you will need to remove the .txt from the end of the filename)
May be that the "document.write(...)" statement is the cause because the use of ".write()" overwrites the entire HTML code of the document the "<script>" included so that its code, your script, cannot be executed.
Can't be that, I tried using a simpler HTML file and it still didn't work. I believe it has something to do with accessing files while on the companion emulator
To use App Inventor, your computer must meet the following system requirements:
Computer and operating system
Macintosh (with Intel processor): Mac OS X 10.5, 10.6+
Windows: Windows XP, Windows Vista, Windows 7+
GNU/Linux: Ubuntu 8+, Debian 5+ (Note: GNU/Linux live development is only supported for WiFi connections between computer and Android device.)
Browser
Mozilla Firefox 3.6 or higher (Note: If you are using Firefox with the NoScript extension, you'll need to turn the extension off. See the note on the troubleshooting page.)
Apple Safari 5.0 or higher
Google Chrome 4.0 or higher
App Inventor does not support Microsoft Internet Explorer. Windows users should use Chrome or Firefox
Phone or Tablet (or use the on-screen emulator)
Android Operating System 2.3 ("Gingerbread") or higher
I should've done this earlier, but the WebView component does work with other websites like http://google.com:
So now it's just figuring out why it's not rendering HTML files that I've uploaded to Media (in other words why it's not rendering HTML files stored locally)
Can you send a .aia file with that project of yours so I can test it on my end? Maybe there is something wrong with the way I set up aiStarter and the emulator
Instead of using the emulator, I went ahead and tested on iOS using the AI Companion app. The page still doesn't load. Also I don't think accessing the file is the main issue because according to the changelogs, http://localhost/ should work:
I've found an old post that apparently updates the old tutorial I was referencing. I followed it exactly and it still doesn't work. I keep getting the "Could not connect to the server" error. I'm including the project I've created. If somebody doesn't mind, please import the project and test it for yourself.
Android or iOS? I guess it doesn't really matter since on my end I tested using both Android emulator and iOS companion app on my own phone, and neither worked. Honestly I'm even more confused why it works for others but not for me.