How to best handle a script closing the HTMLViewer

In my application, I am using two HTMLViewer that is setup as:

HTMLViewer 1 - the main viewer in which a user would use to login to a web vpn. When the web vpn wants to create a connection, it will create a new window in which I redirect to HTMLViewer 2.

HTMLViewer 2 (I am using this in a controlset) - This viewer is used to hold the web vpn connection until the user is done.

So far, this working great; until its time for the web vpn connection to disconnect. If the user logs out of the site in HTMLViewer 1, the web vpn will close the new window it issued previously. When this happens, it actually destroys HTMLViewer2 in which the GUI displays it as being frozen.

to help replicate this, I was able to do this using W3C schools example .

The question becomes… how to best handle this?

  1. Is there a way to capture the javescript calling a window closed event and then allow me to properly refresh HTMLViewer 2?

  2. I added code in the Closed event of HTMLViewer. When the javascript is run, the HTMLViewer.Close event does not fire.

  3. Add a timer that checks to see if HTMLViewer 2 exist… if it doesnt, respond the HTMLViewer 2. If I do it this way, how can I check to see if a control exist?

thank you again in advance.

Do not use the JavaScript close() method, but use the Xojo close method…

I am not so sure the OP actually uses the JS method. Seems it is the VPN which does after connecting. The solution would then be to use ShowURL to open the VPN connection in the default browser instead of HTMLViewer2. If necessary use CancelLoad to intercept the opening of the window by the VPN site and send it to the default browser.

Shao & Michel, thank you for your feedback.

Michel is correct with the web vpn issuing the JS window close method if a user clicks logout on HTMLViewer1.

To provide additional details, the HTMLViewer 1 acts as the web vpn login as well as connection portal to various servers on the network. HTML Viewer 2 is what I wanted to use to maintain the connection while the user is on the network.

What I have done with HTML Viewer 2 is turned it into a controlset in which I am creating dynamtically everytime HTML Viewer 1 New Window Event is called.

in the New Window Event of HTML Viewer 1, I check to see if HTMLViewer2(1) exist and if so… will use HTMViewer2(1).close method before I recreate it. So far… this works well… its just when the user clicks logout out within the HTMLViewer of the Web VPN page.

I performed some additional test and found that if I resize the window or perform a refresh, it will cause HTMLViewer2 to disappear; however, if I check to see if the control exist if HTMLViewer2(1) <> nil then… it comes back saying the control exist.

question… in the cancelLoad event, is it possible to capture what is being sent to it entirely? I if so, I might can use this to parse the data looking for the command to use the Xojo close event instead.

Quick test on W3Schools Tryit Editor shows that the actual JS code is not caught by CancelLoad.

[quote=110345:@Rich Hatfield]I performed some additional test and found that if I resize the window or perform a refresh, it will cause HTMLViewer2 to disappear;
[/quote]

What do you mean ? Resizing a window should not destroy controls ! There must be something else happening here. Check your code.

On windows, when using the W3C schools linked example, when you click on open window and then click on close window… the control will look like its frozen until you resize the gui window causing a refresh. What my other test does is shows that the htmlviewer2 control still exist.

To try things out further, I tested out on my mac. On this platform, I performed the same test… this time… the whole GUI window closes.

video of it happening

so the question still remains… is there a way to prevent a javascript from having this impact on the main application?

Your video is private :frowning:

Maybe you could get out of the freeze by using a timer to invalidate the window so it refreshes without the need to resize.

Have you tried to close HTMLViewer2 ?

I have no idea. You can probably detect it by getting the page source through an HTTPSocket, but I see no simple way to prevent execution of JavaScript. Maybe the MBS HTML plugin could do that. Monkeybread Xojo plugin - HTMLViewer class

ack… I didnt realize it was private… but just made it public video

I will take a look at MBS… thank you again for your input.

http://www.monkeybreadsoftware.net/class-webuidelegatembs.shtml

Look there the Web UI Delegate which allows you to handle close event and destroy the window.

After speaking to Christian… this will only work on OS X… the app is for windows base only.

I will keep digging…

[quote=110582:@Rich Hatfield]After speaking to Christian… this will only work on OS X… the app is for windows base only.
I will keep digging…[/quote]

You may alleviate a bit of the problem by opening a new window to log in instead of using your app main window. So when it closes, it does not close the whole app. Have you tried the timer with self.invalidate to refresh the UI ?

I have tried to invalidate the htmlviewer but no luck.

I will go with your suggestion of threating new browser window event as just that… a new popup window in which if its destoryed by a JS script… it wont affect the main app.

thank you again for all your help :slight_smile: