Getting Text a Value From a HTMLViewer to a TextField.

Hi,

I am trying to find a “simple” way where I can notify my users that an upgrade for my software is available for a desktop app running macOS or Windows. I was thinking that if I would upload a value to a web page and have the HTMLViewer display the value, I could create a message box that notifies the user that an up grade is available.

So if the value was 3 on that webpage, and the user had a stored value of less than 3, a message box would come up saying there was an upgrade available. It could be as simple as just being able to capture a single number from the HTMLViewer, and have it displayed in a TextField.

Is there a way of doing this, without purchasing plugins?

Use the TitleChanged event of the HTMLViewer.

Hi Tim,

Thank you for taking the time to help. I’m not sure what to do with that. There does not seem to be much documentation on how you would use this.

HTMLViewer.TitleChanged(NewTitle as String)

I handle upgrade detection and notification by storing a small text file on the server that contains the contents of a dictionary saved as JSON. The dictionary has a field for the version number and another with update information in HTML format. When the user checks for a new version (or the app does that automatically) a URLConnection is used to retrieve the text file, unpack the dictionary, and check the version number. If it’s more recent than the one the user has, the HTML with the update info is displayed in an HTMLViewer.

Hi James,

Let’s see if I am understanding this correctly… You want to upload an HTML document (to a web server) that contains a value (such as “3”), correct? If that HTML document contains the value “3” in it, you want your Xojo app to notify the user that there is an update. Is this correct?

If so, you wouldn’t even need the HTMLviewer. You can use URLConnection instead, which will allow you to download an HTML file and then check its content for the desired code value.

Here’s a basic summary of how you could do this:

  1. Create an HTML file and put the value “3” in it.
  2. Upload that file to a web server.
  3. Create a New Xojo project and add the URLConnection object to it.
  4. Add a button to the project. When the user clicks on the button, have it use the URLConnection.send() method.
URLConnection1.Send("GET", "https://www.microsoft.com")
  1. Add an Event Handler (ContentReceived) to the URLConnection object.
  2. In the ContentReceived event, the data that’s received from the website will be stored in the “content” variable. You can check it for the desired code value. This will let you know if you need to display a message as to whether the user needs to upgrade or not.

Hope this helps! :slight_smile:

P.S. - Remember that if the web server is NOT using https, that you’ll need to include a plist file, as described on this page in order to allow the data to be received.

Don’t solve problems that have been solved. Use Kaju from Kem Tekinay.

Thank you Beatrix,

I have seen Kaju before in the past, and I thought it looked great, but I found it difficult to follow how to really implement it. The ReadMe file alone is 19 pages long. I know it’s my shortcomings, not the app or the author of the solution. I’m sure it works great.

But just because a problem may be solved, does not preclude that there could be an easier way to solve the same problem, at least in my situation.

All I need to do is generate a single number on a web page that is read by the app. If the number generated from the web page is > then the number stored in the app, the user is notified that there is an update available and provides a button that will download the update. It’s straight-forward and simple… I just need to figure out how to do that.

I’m going to look at Byron’s solution and see if I can figure out how to do what he suggests when I get back to work tomorrow. Again, I am not anywhere as good at coding as the people who look at this forum, so I have to take it as I can, but as always, I really appreciate the help I get here. It is a huge resource.

Thank you

[quote=465912:@James Redway]Hi Tim,

Thank you for taking the time to help. I’m not sure what to do with that. There does not seem to be much documentation on how you would use this.

HTMLViewer.TitleChanged(NewTitle as String)

You use ExecuteJavascript from the Xojo side to cause a javascript function to run in your HTMLViewer. That should then do something like:

document.title = "some string"

where you put in the string the value you want the HTMLviewer to pass back. You then parse that in the event handler

If you just need the latest version number, rather than using an htmlviewer to display the number, you can just put the latest version number in a text file on your web server and read the value. Simplistic approach:

[code]dim http as new HTTPSocket
dim s as String
dim latest_version as double

s = http.get(“http://your_web_server/latest_version_number.txt”,30)

latest_version = cdbl(s)

if latest_version > current_version then
'display new version info here
end if[/code]

[quote=465968:@Tim Streater]You use ExecuteJavascript from the Xojo side to cause a javascript function to run in your HTMLViewer. That should then do something like:

document.title = “some string”
where you put in the string the value you want the HTMLviewer to pass back. You then parse that in the event handler[/quote]

Thank you Tim, that was a little past my skills, but I appreciate the help.


[quote=465922:@Byron Minick]Create an HTML file and put the value “3” in it.
Upload that file to a web server.
Create a New Xojo project and add the URLConnection object to it.
Add a button to the project. When the user clicks on the button, have it use the URLConnection.send() method.
URLConnection1.Send(“GET”, “https://www.microsoft.com”)
Add an Event Handler (ContentReceived) to the URLConnection object.
In the ContentReceived event, the data that’s received from the website will be stored in the “content” variable. You can check it for the desired code value. This will let you know if you need to display a message as to whether the user needs to upgrade or not.[/quote]

Thank you Bryon for taking the time to try to help. That did work, but it returned all the html code in the text box and not the single value. So it was difficult to parse that out even on a simple web page.

Thank you Johnathan. That worked also, but for some reason it was adding these weird symbols like diamonds with question marks in them on the Mac and different weird symbols on Windows.

[quote=466067:@Scott Griffitts]dim http as new HTTPSocket
dim s as String
dim latest_version as double

s = http.get(“http://your_web_server/latest_version_number.txt”,30)

latest_version = cdbl(s)

if latest_version > current_version then
'display new version info here
end if[/quote]

Thank you Scott that worked the best. It just displays the number in the textbook. Thank you so much. That is just what I was looking for.

So this the code I ended up using.

[code]Dim http As New HTTPSocket
Dim s As String

s = http.get(“https://knightlite.com/update/test/update.txt”,30)

txtNewVersion.Text=s

Dim N As Integer
Dim U As Integer

N=Val(lblReleaseNum.Text)
U=Val(txtNewVersion.Text)

If U > N Then
lblUpgrade.Visible=True
cmdDownload.Visible=True
End If[/code]

I added this code to the Open Event of my Splash screen. If there is an update available, a label will appear telling the user to download the new version. A button also appears that sends the customer directly to the download page.

This is what I was looking for. A nice, simple way to communicate with a customer directly through the app without a lot of work.

Thank you again for all of your help. I really appreciate you all spending the time to help me.

Just keep in mind my simple example didn’t include any error handling. What if the file is missing, or the request times out or the user doesn’t have an internet connection? You should also verify that your result is in fact a number and manage the encoding of what you read in. The diamonds you mentioned are an indication of an encoding issue: https://blog.xojo.com/2013/08/20/why-are-there-diamonds-in-my-user-interface/

You also need to consider security; you’re heading down the path of providing an update system, therefore you should start thinking about protecting your customers now, before you end up with a system that inadvertently turns your application into a MacKeeper, malware or virus delivery system.

I believe that Kaju has you covered for two main issues that I am aware of.

  1. Validating that the data you receive from your server came from you.
  2. When installing the update, you need to validate that the application came from you.

Simply having the files on your server is not a secure means of ensuring that this data came from you.