How to return contents of a div inside a webhtmlviewer?

Thanks to some much-appreciated help Michel B gave me a while back and another post, the code below at least allows me to display an alert of the contents of the div in the webhtmlviewer, and also alert the url of the file being displayed in the webhtmlviewer, but what further code do I need to get the contents of the div in the webhtmlviewer returned back into a variable in Xojo?

  dim theelementid as string = "inputdiv"
  dim thejavascript as string 
  thejavascript = thejavascript + "var HTMLViewer= document.getElementById('"+HTMLViewer1.ControlID+"');"
  thejavascript = thejavascript + "var VieweriFrame=HTMLViewer.getElementsByTagName('iframe');"
  thejavascript = thejavascript + "var viewerDom=VieweriFrame[0].contentDocument ;"
  //alert the url
  thejavascript = thejavascript + "alert(VieweriFrame[0].contentWindow.location.href);"
  //alert the div contents
  thejavascript = thejavascript + "alert(viewerDom.getElementById('"+theelementid+"').innerHTML);"

The div contains up to 200 lines of html.

Thanks in advance!

Instead of the HTMLViewer, you may want to use an HTMLArea from the WebSDK instead, so you can use in JavaScript Xojo.TriggerServerEvent.

See the Extras folder next to the Xojo executable, the WebSDK folder. Inside, check WebControlSDK.pdf . Also, look at the HTMLArea.xojo_binary_project in WebSDK/Examples.