Stay On Page

I would really like a “Stay on Page” property in the Web Session.

If You go to the “Eddys” demo on the xojo.com site: (http://demos.xojo.com/cgi-bin/orders/orders.cgi#10046)

Any you then hit the browsers back button You get a nice dialog that asks if you wish to leave the site.

Was this added to 2013?

The WebSession.ConfirmMessage property was added in 2011r2, but we only started using it with the Eddie’s Electronic’s sample project in 2013r1.

Nice!

This one has been very useful. We tend to set the message when we’re in an edit state (or not saved). It at least keeps users from accidentally leaving the site or quitting the browser.

I also put the following code in the app.HTMLHeader section… which keeps the ‘Backspace’ key from causing the browser to go ‘Back’ should the user accidentally not have the cursor in a textfield/textarea at the time. This helps…

<script type="text/javascript"> 
function checkShortcut()
{
if(event.keyCode==8 ¦¦ event.keyCode==13)
{
return false;
}
}
</script>

<body onkeydown="return checkShortcut()">

<input type="text" onFocus="x=true" onBlur="x=false"> 

Eric, I don’t see any “HTMLHeader” property in the App class? Am I being stooopid? Or do you use the Session.PrepareSession event to insert your script into the HTMLHeader?

In the app inspector,bottom item.

That would work too.

Would it be possible to set an event instead of a property to manage this inside our apps ?

No. Remember, you can’t directly respond to things happening on the browser because by the time the message gets to the server, the browser has gone on to other things. This is one of those events where you must return a value in the same JavaScript event as it was triggered and since you can’t do that with a round trip to the server, it must be done with a pre-stored Boolean.

@Greg O’Lone
You are right ! I often forget this problem since I regularly look for workarounds by Javascript.
That said, a solution must be found to prevent the user from accidentally leaving the application. The “ConfirmMessage” is not appropriate.
What is possible in the state?

Why is the ConfirmMessage not appropriate? That’s what the browsers offer us for this functionality.

By unappropriate, I meen that the way of displaying the message is not in the app.

[quote=19660:@Eric Brown]I also put the following code in the app.HTMLHeader section… which keeps the ‘Backspace’ key from causing the browser to go ‘Back’ should the user accidentally not have the cursor in a textfield/textarea at the time. This helps…

[code]

[/code][/quote]

Can a body tag be placed in the HTMLHeader?

From what I see the Body stuff does not stay in Head, but simply gets merged with the normal Body.

So I just tested it…

Before:

<body style="margin: 0px;" onload="Xojo.begin('318FA780279DAD2464758B32C20DFD76')" onorientationchange="Xojo.view.sizing.rotated()">

After:

[code]

[/code]

Doesn’t seem to be in the right place…

No. You can’t put a body tag in the header. Any “merging” you are seeing is being done by the browsers themselves. And the behavior will likely be different on different browsers.

It is relatively easy to modify the tag in JavaScript with GetElementsByTagName.