I would like to know, thanks.
Not directly. You will need HTTPSocket or HTTPSecureSocket to get the url and save the content to a file. Then use HTMLViewer.LoadPage
or you use our MBS Plugins and use HTMLTextMBS / IEHTMLTextMBS methods.
I forgot to add that I was talking about html rendered via Javascript, without a HTML File. Or would I have to use Javascript itself to save the file?
Thanks,
Shane.
This is how I get the source code from a HTMLViewer⊠I do this as a sub-class, but I am sure you can think of a way to do it without sub-classing if need beâŠ
// computed property
[code]Source As String
Get
me.ExecuteJavaScript âwindow.status = document.getElementsByTagName(âbodyâ)[0].innerHTML;â
Return me.CallbackData
End Get
Set
End Set[/code]
// property
Private CallbackData As String
// event handler
Sub StatusChanged(newStatus as String)
if (newStatus <> "") then
me.CallbackData = newStatus
end if
End Sub
When you request the source computed property, it runs the javascript and sets the window.status property to the source⊠Once the window.status has been changed, the event handler is called and it stores the window.status in to the CallbackData property, which is then returned from the computed property⊠Yes, it does work, I use it a lot in my programâŠ
[quote=40231:@shao sean]This is how I get the source code from a HTMLViewer⊠I do this as a sub-class, but I am sure you can think of a way to do it without sub-classing if need beâŠ
// computed property
[code]Source As String
Get
me.ExecuteJavaScript âwindow.status = document.getElementsByTagName(âbodyâ)[0].innerHTML;â
Return me.CallbackData
End Get
Set
End Set[/code]
// property
Private CallbackData As String
// event handler
Sub StatusChanged(newStatus as String)
if (newStatus <> "") then
me.CallbackData = newStatus
end if
End Sub
When you request the source computed property, it runs the javascript and sets the window.status property to the source⊠Once the window.status has been changed, the event handler is called and it stores the window.status in to the CallbackData property, which is then returned from the computed property⊠Yes, it does work, I use it a lot in my programâŠ[/quote]
Thanks.
I am having a problem with my code that writes to the document.
[code] Dim BtnDefault As String
If ColumnsToUse.ListIndex = 0 Then
BtnDefault = âdocument.write(â"<button class="âbtn btn-defaultâ">Button"");"
HTMLViewer1.ExecuteJavaScript(BtnDefault)
End If
[/code]
Yet, when I click the button, nothing happens and when I view the HTML source (right click>>view source), the html code hasnât been written.
Any ideas?
Youâre probably getting a JavaScript error. The code youâve written will be evaluated as:
document.write("<button class="btn btn-default">Button</button>");
Notice the quotes? I suggest escaping the innermost ones or making them single quotes around the class.
[quote=40247:@Greg OâLone]Youâre probably getting a JavaScript error. The code youâve written will be evaluated as:
document.write("<button class="btn btn-default">Button</button>");
Notice the quotes? I suggest escaping the innermost ones or making them single quotes around the class.[/quote]
Nope. Using single quotes has the javascript show as actual Xojo code. I thought that is what double quotes were for. Because you quote the html you want to output.
HTMLViewer1.ExecuteJavaScript "document.write(""<button class='btn btn-default'>Button</button>"");"
Well, after more than six yearsâŠ
That @shao seanâs code is great for grabbing the content of the HTMLViewer, that goes without saying. Thanks to Shao.
On the other end, is there a way to grab the content when the HTMLViewer loads a pdf file?
In fact, the element passed in Shaoâs code is âbodyâ:
Get
me.ExecuteJavaScript "window.status = document.getElementsByTagName('[b]body[/b]')[0].innerHTML;"
Return me.CallbackData
End Get
but when the HTMLViewer loads a pdf file, âbodyâ or âhtmlâ do not contain any proper text. The pdfâs content is referred in
<embed⊠and name=âpluginâ, as shown below.
Given these data (copied from a pdf file open in Safari > Developer > Web Inspector) is there any modification by which Shaoâs original code could grab the text itself?
I guess the answer is âNoâ. But maybe some guru may prove me wrong.
Thank you.
6 years later, plus 7 months laterâŠdid you figure this out? I have some javascript that generates a pdf, and would like to save it locally.
For regular HTML you could execute some JavaScript like this using the newer functionality of the HTMLViewer:
window.executeInXojo(document.getElementsByTagName('html')[0].innerHTML);
Iâm not sure how youâd do it with a PDF.
Itâs quite frustrating, as this would be perfect. I have the pdf created and in a blob format, but canât figure out how to get it out of the htmlviewer. LOL I can view it in an iframe, but the little save icon doesnât do itâs job, it just clicks.
Then maybe:
window.executeInXojo(myPDFBlob);
As far as I can tell, you can only transmit strings and numbers with that. But maybe I can convert the blob to a string, get it into Xojo, and then convert it back somehow. Iâll have to play around.
You can use JavaScriptâs btoa
function to convert to BASE64 that you can then decode in Xojo.
Unfortunatelly I did not.
I couldnât do it with btoa (invalid characters), but using FileReader to convert to Base64, then DecodeBase64ing it in Xojo seems to work. Holy cow!
ThanksâŠ
Happy to help.