How to open Xojo Webpage with HTML button

How do I open a Xojo Webpage with an HTML button?

I can open html webpages with html button, Xojo webpage with Xojo buttons, and html pages with Xojo buttons, but can’t seem to figure out how to open a Xojo webpage with an HTML button.

After working on this for a week, I am going to ask to see if someone has performed this before. My guess is that I need an addeventlistener and triggerserverevent, but I can’t seem to make it work.

Below is a clean project (without all of my messy attempts) that shows an html button in WebPage1.MyWebsiteHTMLcode constant, and there is a Webpage2 to be opened.

NewWebPage.xojo_binary_project

Any help is appreciated and I am heading out for a well-deserved cup of coffee :slight_smile:

HTML has no idea about the Xojo web app. Likewise, Xojo has no idea about the HTML. What you want to do is tell Xojo to display WebPage2.

Here is the simplest way.

MyHTML :

[code]

Open up Xojo webpage with HTML button



My HTML Button

[/code]

Session:

Sub HashTagChanged() System.DebugLog me.HashTag if me.Hashtag = "WebPage2" then WebPage2.Show end if End Sub

You can use WebSDK Xojo.TriggerServerEvent() instead window.location.replace() to avoid modifying the URL.

Hi Michel,

Thank you for your quick response.

As always, your answer is spot on. Thank you Doctor :slight_smile:

You’re welcome, Eugene.

I spoke to soon.

The window.location.replace works well, and I am missing something with Xojo.triggerServerEvent.

<button id="MyHTMLButton" onclick="window.location.replace('#WebPage2');">My HTML Button</button> This triggers the HashTagChanged event and works.

<var s = "#WebPage2;"> <button id="Xojo.triggerServerEvent('" + Self.ControlID + "','HashTagChanged', [s]);">My Trigger Button</button> The HashTagChanged event does not fire.

What am I missing on the triggerServerEvent command?

Your JavaScript should go into onclick, not id :

<var s = "#WebPage2;"> <button id="MyHTMLButton" onclick="Xojo.triggerServerEvent('" + Self.ControlID + "','HashTagChanged', [s]);">My Trigger Button</button>

Hi Michel,

Sorry, I am not understanding how to implement a triggerServerEvent.

NewWebPageTriggerEvent.xojo_binary_project

Xojo jand Feedback just created a set of large dump files when sending this to you … be right back

Here are a few attempts that I tried:

  1. copy and pasted this code in the Default Value for WebPage1.MyWebsiteHTMLCode and Session.HashTageChanged does not fire.

[code]

Open up Xojo webpage with HTML button



My Trigger Button [/code]
  1. Created a function for the button to call in App.HTMLHeader, and was not able to have the Xojo.TriggerServerEvent Fire.

Thanks for your continued patience.

I looked at your project. There are several errors in there.

1 . Your HTML code has to be pure HTML and JavaScript. Not Xojo code. Here is what I did :

[code]

Open up Xojo webpage with HTML button



My Trigger Button

[/code]

In order to correctly initialize the HTML with your HTMLArea’s Control ID, here is what you do in open :

Sub Open() Me.MyHTML = Replace(MyWebsiteHTMLCode, "ControlID", me.ControlID) //load HTML code with the HTML button End Sub

2 . Now you must add the ExecuteEvent handler to your HTMLArea instance. That is where you get the result of you JavaScript event :

Function ExecuteEvent(Name as String, Parameters() as Variant) As Boolean Msgbox "Click "+Parameters(0) End Function

So you have two different ways : change the URL HashTag, or raise ExecuteEvent within your WebSDK control.

Michel,

Thank you for your guidance and patience. Both URL Hashtag and ExecuteEvent methods work well when using your instructions.

All the best,

Eugene

You’re welcome. With some luck, we are going to see a “I Wish I Knew How To Xojo Web” one of these days :slight_smile: