app.EnableBackKey()

59 views
Skip to first unread message

Soni Kumari

unread,
Aug 20, 2026, 2:30:55 AM (8 days ago) Aug 20
to DroidScript
I build a html project and placed app.js script in head 
And access my html project in webveiw 
My html projects use app.EnableBackKey(false) function OnBack(){
// To dismiss current active window 
}

But in webveiw it back button get false but function Onback() doesn't work
In html standalone it works but not in webveiw so that i can't dismiss active window by pressing back button  please help me to achieve it 



Alan Hendry

unread,
Aug 20, 2026, 5:14:46 AM (8 days ago) Aug 20
to DroidScript
HI,
Not sure what you mean.
This seems to work
Regards, ah

<html>
<head>
    <meta name="viewport" content="width=device-width">
    <script src="ds:/Sys/app.js"></script>
</head>
<script>
    function OnStart() {
        app.ShowPopup( "HTML Rocks!" );
        app.EnableBackKey( false )
    }
    function OnBack() {
        app.ShowPopup( "You pressed the Back button" )
    }
</script>

<style>
body { background-color: #ffffff; }
    .hello  {
        font-size: 42;
        width: 100%;
        margin-top: 2em;
        text-align: center;
        color: blue;
    }
</style>

<body onload="app.Start()">
<div class=hello> Hello World! </div>
</body>
</html>

Soni Kumari

unread,
Aug 20, 2026, 5:30:25 AM (8 days ago) Aug 20
to DroidScript
I tried your sample  code but function OnBack not triggered in webveiw 
function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

     web = app.CreateWebView( 1, 1, "Progress" );
     web.SetOnProgress( web_OnProgess );
     lay.AddChild( web );

     app.AddLayout( lay );

     web.LoadUrl( "your_sample_code.html" );
}

function web_OnProgess( progress )
{
     app.Debug( "progress = " + progress );

Alan Hendry

unread,
Aug 20, 2026, 5:59:33 AM (8 days ago) Aug 20
to DroidScript
HI,
Still not sure what you mean
Can you post example code?
This also works
Regards, ah

function OnStart() {
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );
    web = app.AddWebView( lay,1, 1, "Progress" );
    web.SetOnProgress( web_OnProgess );
    app.AddLayout( lay );
    web.LoadHtml( "<h1>Header 1</h1><h2>Header 2</h2><h3>Header 3</h3><h4>Header 4</h4><h5>Header 5</h5><h6>Header 6</h6><p>Hello, World!</p>" )
    app.EnableBackKey( false )
}

function web_OnProgess( progress ) {
     app.Debug( "progress = " + progress );
}
function OnBack() {
   app.ShowPopup( "You touched the Back key" )
}

Soni Kumari

unread,
Aug 20, 2026, 6:07:51 AM (8 days ago) Aug 20
to DroidScript
Ii have a html file with multiple window in that document like section one second 2 like full window 
I want if any second of window is currently opened then press back button then dismiss that active window and back to home if no active section open in that html fille home means: not back to main js file, only come at that html document home

I tried app.EnableBackKey(false) with OnBack() in the web view it us not working 
Not working means: if i open any window in that html file which is showing through webview, isn't that dismiss by pressing back button

Soni Kumari

unread,
Aug 20, 2026, 6:22:05 AM (8 days ago) Aug 20
to DroidScript

This is the spk file to check 
Also run 't.html" file alone in html template where it works back button for dismiss window but in webveiw it is not working 
Camera Demo.spk

Alan Hendry

unread,
Aug 20, 2026, 7:44:30 AM (7 days ago) Aug 20
to DroidScript
HI,
I changed your Camera Demo.js
function OnStart() {
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );
    web = app.AddWebView( lay,1, 1, "Progress" );
    web.SetOnProgress( web_OnProgess );
    app.AddLayout( lay );
    web.LoadUrl( "t.html" )

    app.EnableBackKey( false )  
}
function web_OnProgess( progress ) {
     app.Debug( "progress = " + progress );
}
function OnBack() {
    app.ShowPopup( "You touched Back" )
}
The OnBack works
In your html when the user touches the <-- arrow
it runs function goHome.
Do you want DS OnBack to run goHome?
function OnBack() {
    app.ShowPopup( "You touched Back" )
    web.Func( "goHome" )
}
Regards, ah


Soni Kumari

unread,
Aug 20, 2026, 8:03:27 AM (7 days ago) Aug 20
to DroidScript
Thanks! It worked!
But there is still problem 
I want to use in app.CreateDialog() 
I done this and add webview but as soon as i press back button whole whole dialog dismiss 
I used also "NoCancel" but not work 

I want: like: open my app, on main home which is app.js and there are some layouts when click on one button then show that html file dialog 
If there is no active window in that dialog ( which show t.html) then dismiss the whole dialog and come on main app home 
If there is active window then work back button for dismiss the window and if none of left the back to main layout home

Alan Hendry

unread,
Aug 21, 2026, 3:57:31 AM (7 days ago) Aug 21
to DroidScript
HI,
Not sure what you are trying to do
web.Func(function,parms)
can invoke functions within the webview
web.Execute(code, callback)
can run any code in the webview
and send a result to the callback.
Regards, ah
Reply all
Reply to author
Forward
0 new messages