HTMLView to BlitzMax Communication
BlitzMax Forums/BlitzMax Programming/HTMLView to BlitzMax Communication
| ||
| I have found out that HTMLViewRun can be used to send information to the HTML, yet there doesn't seem to be any way to send information back. Is there a way to send information from an HTML page in an HTMLView gadget to the parent program? I am writing the program and the HTML pages that are involved, so is there any javascript code the page can call to send a request or event to the parent program? |
| ||
This may not be the best way to do it but it works for strings of data coming from the browsers
SuperStrict
Import maxgui.drivers
Global mainWindow:TGadget = CreateWindow("myWindow", 100, 100, 1024, 768, Null, WINDOW_TITLEBAR | WINDOW_RESIZABLE)
Global html:TGadget = CreateHTMLView(0, 0, 1024, 768, mainWindow, HTMLVIEW_NONAVIGATE)
HtmlViewGo(html, "Jupiter_moon.htm")
Repeat
WaitEvent
Select EventID()
Case EVENT_GADGETACTION
If EventSource() = html
Print EventText() 'this will be the link that was sent by your JS code
End If
Case EVENT_WINDOWCLOSE
Exit
End Select
Forever
For the HTML do this
<script>
function returnData(d)
{
var lo = document.getElementById('dlink');
lo.href=d;
lo.click();
}
</script>
<body>
<a id="dlink" href=""></a>
</body>
the dlink anchor is used to send the link data to your code via eventtext. Works in IE not sure if the JS will work in other browsers. |
| ||
This is still rough, but I think this is the route I will take
Strict
Import maxgui.drivers
Global window:TGadget=CreateWindow("My Window",30,20,600,440,,15|WINDOW_ACCEPTFILES)
Global htmlview:TGadget=CreateHTMLView(0,0,ClientWidth(window),ClientHeight(window),window,HTMLVIEW_NONAVIGATE)
SetGadgetLayout(htmlview,1,1,1,1)
HtmlViewGo(htmlview,"Test.html")
While WaitEvent()
Select EventID()
Case EVENT_GADGETACTION
Print processMsg(EventText())
Case EVENT_WINDOWCLOSE
End
End Select
Wend
Function processMsg:String(msg:String)
msg=Right(msg,Len(msg)-4)
For Local i:Int=32 To 255
Print "%"+Right(Hex$(i),2)
msg=Replace(msg,"%"+Right(Hex$(i),2),Chr(i))
Next
Return msg
EndFunction
Test.html
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function Jump()
{
var param2=1
window.location.href = "msg:toBeParsed('One',"+param2+")";
}
</script>
</head>
<body>
<a href="msg:Just Some Text">Click Here<a>
</body>
</html>
|
| ||
| is clicking on the link by a user required? if so you may want to have javascript send a click event to that link so your program can initiate the data transfer without user intervention. You also want to check to make sure that the object that fired the gadgetaction is in fact your htmlview. |
| ||
| Thank you for reminding me to check for that. It appear that javascript navigation is handled the same as a user clicking a link. |