Trigger a WebPopUp In Code?

Hey all,

Is there any way to trigger a mouse click action via code for a WebPopUp? I don’t want to set the value of the pop-up. I want to trigger the pop-up menu that you get when you click on it but I want to do it via code.

Is this possible?

Thanks,

Jon

In JavaScript the command click() should do that.

OK. Cool. But can you tell me how I can implement that? Say I click another control that I want to use to drive the pop-up to open.

Would I do something like (and the syntax might not be right so forgive me):

PopUpMenu.ExecuteJavaScript(“click();”)

?

Maybe I’ll go try that…

[quote=92306:@Jon Ogden]OK. Cool. But can you tell me how I can implement that? Say I click another control that I want to use to drive the pop-up to open.

Would I do something like (and the syntax might not be right so forgive me):

PopUpMenu.ExecuteJavaScript(“click();”)

?

Maybe I’ll go try that…[/quote]

The command would use the ExecuteJavaScript method of a button for instance. See http://documentation.xojo.com/index.php/WebControl.ExecuteJavaScript

Problem is, I tried

Me.ExecuteJavascript("document.getElementById('" + PopupMenu1.ControlID + "_inner').click();")

And it simply does not work :frowning:

The same command used in a desktop application HTMLViewer works on a loaded page. So I have no idea what maybe going on.

Unless someone has a solution to do what you ask, you may want to consider a couple possibilities :

  • Use PresentContextualMenu to show a contextual menu exactly over the PopupMenu with the same options. It is fairly simple and provides the same functionality. Problem is, the appearance is not the same, and the contextual menu has a small blue triangle underneath. It can be confusing in terms of UI.

  • Use a listbox. I posted a way to use a listbox as a menu in Call contextualmenu on touch devices - Web - Xojo Programming Forum you could use to do that. You set the listbox where the dropped menu would appear, and make it invisible. To open the popupmenu, make it visible. In terms of appearance, you can get extremely close to the real popupmenu drop down.

If you think the second solution is of interest, I may try to build a working project. I will need a description of your popumenu to emulate it : size, items…

This might be a browser security model thing. I bet you can invoke that simulated click from another client object’s “onclick” event, but sending it from the server is a no-go.

That is what I thought. But then, why should it raise a security exception as the JavaScript is on the same domain as the WE, and should be seen as part of the code from the app ?

Just for the fun, I just quickly created a small sample of what a listbox employed as a simulated dropdown from a popupmenu would look like. On the left, the real thing, on the right, the simulation. Of course, tuning will make it a lot closer. But take it as a proof of concept. Anyway, if no other solution is available, it is a workaround.

Thanks for your help on this. The PresentContextualMenu is what I did have originally. Works very well for the most part except if the menu is long enough to go beyond the edge of the browser window, there is no way to scroll it. The pop-up menus scroll. If scrolling was enabled for the contextual menus, that is what I would want.

[quote]

  • Use a listbox. I posted a way to use a listbox as a menu in https://forum.xojo.com/8931-call-contextualmenu-on-touch-devices you could use to do that. You set the listbox where the dropped menu would appear, and make it invisible. To open the popupmenu, make it visible. In terms of appearance, you can get extremely close to the real popupmenu drop down.

If you think the second solution is of interest, I may try to build a working project. I will need a description of your popumenu to emulate it : size, items…[/quote]

This might be - particularly if it scrolls…

Not sure if it raises an exception or just fails silently or what. The reason usually goes back to “can you make the browser play audio or video outside a direct click from the user?” Mobile Chrome tends to be the most stringent.

Yes it does. It is a listbox, after all :wink:

Great. I’ll try displaying a listbox then with my items when the user clicks on the control. That could be what I am looking for.

Look at the posts I mentioned above for code that makes the listbox behave as a menu : selection, click, etc.

I just did and have it open in another tab. And I also downloaded your example project. :slight_smile:

If it raised an exception I guess it would trigger the infamous unknown exception message. It simply does nothing. The Xojo method works, though, as a JavaScript message will pop up nicely. Somehow, it is click() that fails.