2017년 6월 11일 일요일

JavaScript to pass information from HTML to WebViewString


I'm managing a list of proverbs in the WebView component as follow;
document.write(window.AppInventor.getWebViewString()); as the JavaScript to receive the HTML content or <body>.

The WebViewString is set to:

<ul>
<li>Maisha  mazuri</li>
<li>tenda wema nenda zako</li>
</ul>

Now I wanted to extract the <li>( innerHTML) with an onclick event and share it using the SHARING component.
I tried this <li onclick="javascript:window.AppInventor.setWebViewString(this.innerHTML);"> 
but failed to get the text via window.AppInventor.setWebViewString() as shown in this tutorial.
webviewstring.aia

Please, I need your Help!

--
Three things to try:

Check that "this.InnerHTML" actually contains what you want back?

Remove the word javascript:

onclick="window.AppInventor.setWebViewString(this.innerHTML);"

Might it need to be in a "link" ?

<a href="javascript:;">onclick="window.AppInventor.setWebViewString(this.InnerHTML)"></a>
or
<a href="javascript:;">onclick="window.AppInventor.setWebViewString('this.InnerHTML')"></a>

-- 
Also , just an observation (based upon what you have disclosed):

If you are seeking to collect the same information as you are feeding the html, why not setWebViewString as an index number, collect that, and use the index to call up the data from a list?

Unless I have missed something?

-- 
Thanks a lot Tim.

I tried these methods on Samsung Galaxy Note 2(android 4.1.2), it worked very well.
But failed on other devices (android 4.4.1 and higher)...


--

댓글 없음:

댓글 쓰기