Android Question (closed) webViewExtras and imageMap

anOparator

Active Member
Licensed User
Longtime User
Am trying to get the alt value from an image map by using the "saveHTML WebViewExtras" sample project.
B4X:
In the HTML:
<map name="pn13">
<!-- #$-:Image map file created by GIMP Image Map plug-in -->
<!-- #$-:GIMP Image Map plug-in by Maurits Rijk -->
<!-- #$-:Please do not edit lines starting with "#$" -->
<!-- #$VERSION:2.3 -->
<!-- #$AUTHOR:oper8or -->
<area id=1 shape="rect" coords="134,1,188,28" onclick="openNav(this)" alt="1" target="pn" href="" />
<area id=2 shape="rect" coords="134,56,188,83" onclick="openNav(this)" alt="2" href="" />
<area id=3 shape="rect" coords="231,102,285,132" onclick="openNav(this)" alt="3" href="" />
</map>

<script>
function openNav(element) {
   var alt = element.getAttribute("alt");
   document.getElementById("tname").innerHTML = alt;   <!-- How does this happen? -->
}
</script>
In Main.b4a:
B4X:
Sub WebView1_PageFinished (Url As String)
   Dim Javascript As String
   'Javascript="B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
   Javascript="B4A.CallSub('ProcessHTML', false, document.documentElement.innerHTML)"
   Log("PageFinished: "&Javascript)
   WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub
I've read http://www.b4x.com/forum/additional...al-updates/12453-webviewextras.html#post70053 for details of the second parameter callUIThread, and many other articles.
:banghead
 

Attachments

  • myMap.zip
    26.7 KB · Views: 197

anOparator

Active Member
Licensed User
Longtime User
If you don't need to show the html then use OkHttpUtils2 to download the html and parse it directly or with jTidy. It will probably be simpler.
This is an Assets file that is copied to File.DirInternal, the saveHTML sample was only used as a webViewExtras template.
It seems that jTidy converts the html to an XML file to then use an XML parser, when I'm trying to get an "alt =" value each time I click hotspot on imageMap.
B4X:
<img src="pnap13.png" width="320" height="480" border="0" usemap="#pn13" />
<map name="pn13">
<area id=1 shape="rect" coords="134,1,188,28" onclick="openNav(this)" alt="1" target="pn" href="" />
<area id=2 shape="rect" coords="134,56,188,83" onclick="openNav(this)" alt="2" href="" />
jTidy looks handy for some other things I have in mind, thanks.
edit:
In the map changed:
<area id=1 shape="rect" coords="134,1,188,28" onclick="openNav(this)" alt="1" target="pn" href="" />
to
<area id=1 shape="rect" coords="134,1,188,28" onclick="openNav(alt)" alt="1" href="" />
It shows alt= value for all map segments in a web browser Alert box, next step is to make the Main activity happy :)
 
Last edited:
Upvote 0
Top