언어 설정

Menu
Sites
Language
How to use mobile back button with my application

Hi,

I have develop a TIZEN application in which when i press mobile back button then it not open the previous page.

How to use mobile back button (given by SAMSUNG) with my application.

How to make mobile button to open previous page of application, please help me

 

 

Thanks and regard

TIZEN application developer

Mohit Kumar

 

 

 

 

Responses

19 댓글
AVSukhov

Hello,

You may use following code:

var backEventListener = null;

var unregister = function() {
    if ( backEventListener !== null ) {
        document.removeEventListener( 'tizenhwkey', backEventListener );
        backEventListener = null;
        window.tizen.application.getCurrentApplication().exit();
    }
}

//Initialize function
var init = function () {
    // register once
    if ( backEventListener !== null ) {
        return;
    }
    
    // TODO:: Do your initialization job
    console.log("init() called");
    
    var backEvent = function(e) {
        if ( e.keyName == "back" ) {
            try {
                if ( $.mobile.urlHistory.activeIndex <= 0 ) {
                    // if first page, terminate app
                    unregister();
                } else {
                    // move previous page
                    $.mobile.urlHistory.activeIndex -= 1;
                    $.mobile.urlHistory.clearForward();
                    window.history.back();
                }
            } catch( ex ) {
                unregister();
            }
        }
    }
    
    // add eventListener for tizenhwkey (Back Button)
    document.addEventListener( 'tizenhwkey', backEvent );
    backEventListener = backEvent;
};

$(document).bind( 'pageinit', init );
$(document).unload( unregister );

 

mohit kumar

Hi,

How can i get tizenhwkey key.

 

 

thanks and regards

 

Mohit Kumar

Tharun Reddy

respected sir,just i have to copy this code and paste it in js file so that it works right??

Tharun Reddy

it is the same code for back button in web simulator also??

AVSukhov

Hello,

Also you can find sample if create new project in IDE using Multi Page Application template

Seoghyun Kang

Hello,

 

If you want to use the hardware back button, please refer the following code.

// Bind hardware back button.
window.addEventListener('tizenhwkey', function onTizenHwKey(e) {
    if (e.keyName === 'back') {
        // TODO
    }
});

 

There are many solution to return the previous page. It depends on your page movement processing.

Ex 1. Normal type

window.history.back();

 

Ex 2. TAU

tau.back();

 

 

Please refer it.

 

mohit kumar

Hi,

Thank you so much.TIZEN is very good

 

Very Heppy TIZEN

 

 

 

 

thanks and regards

Mohit Kumar

 

 

 

 

Alex Dem

Hi,
just fyi, from dev-guide: In IDE->Help->Help Contents there is regarding hardware keys handling: Web App Programming > Basics of Web App Programming->Hardware Keys
I did not find appropriate in online dev-guide.
Alexey.

mohit kumar

Hi,

I want to share my TIZEN web application on facebook.How can i do that,please help me.

 

thanks in advance

 

Thanks and regards

Mohit Kumar

 

Seoghyun Kang

What is the meaning of "share"?

 

Do you want to share the timeline for Advertising on Facebook?

ex) Add the link : https://developers.facebook.com/docs/plugins/share-button

 

If it is not , please write it in detail and please share your code if possilbe.

mohit kumar

Hi Seoghyun,

I want to create a button in my TIZEN web application and if user click on the  button then my application will share on facebook wall or share to all my friend.

Now i am shareing my code please follow the link

https://github.com/mohittripathi/geniusquiz

Please help me

 

thanks and regards

Mohit Kumar

 

Palitsyna

Hello,

may be this link will help you: https://developers.facebook.com/docs/sharing/reference/share-dialog

AVSukhov

Hello,

For example you can use following in Web app:

Open facebook url from app with browser (better in separate window)
for example: https://www.facebook.com/sharer/sharer.php
perform authentication,
share any url

mohit kumar

Hi,

Its workin,but i want to use hardware back button,once user click on hardware back button the it should exit from application.

 

By clicking on hardware back button it should be exit from application.

 

 

Thanks in advance

Mohit Kumar

 

Palitsyna

Hello,

add this code to init function:

// add eventListener for tizenhwkey
document.addEventListener('tizenhwkey', function(e) {
	if(e.keyName == "back") {
		try {
			tizen.application.getCurrentApplication().exit();
		} catch (error) {
			console.error("getCurrentApplication(): " + error.message);
		}
	}
});

 

AVSukhov

Hello,

You can use Application API to exit from you app. More info:

https://developer.tizen.org/dev-guide/2.3.0/org.tizen.web.apireference/html/device_api/mobile/tizen/application.html#Application::exit

Tharun Reddy

hi am tharun,

in my application i have to provide the back button after seeing this mails i got the code for back button but,now where should i write this code??do i should write to each and every of my html page??

Armaan-Ul- Islam

If you use the comple solution shared by AVSukhov in first response you can set the code anywhere in js file, just include the file in html.

 

Or you can write code inside window onload() function then include the js file.

 

window.addEventListener("load",function(event) {
   
    tizen.application.getCurrentApplication().exit();
    // OR
    window.history.back();
    // OR
    tau.back();
    // based on need

},false);
André Reus

hi, currently almost all of the sample/template apps come with this feature in Tizen Studio. If you define your home/main page id as 'main' and check a condition for this ID to exit the app. And for other id simply call window.history.back(); to go to previous page. 

window.addEventListener( 'tizenhwkey', function( ev ) {
    	if( ev.keyName === "back" ) {
		var page = document.getElementsByClassName( 'ui-page-active' )[0],
			pageid = page ? page.id : "";
		if( pageid === "main" ) {
			try {
			   tizen.application.getCurrentApplication().exit();
			} catch (ignore) {
		}
		} else {
			window.history.back();
		}
	  }
	} );

 

 

<div class="ui-page ui-page-active" id="main">
    	<header class="ui-header">
			<h2 class="ui-title">First Page</h2>
		</header>
		<div class="ui-content content-padding">
			
		</div>
</div>