|
本帖最后由 hisoon 于 2017-1-12 13:04 编辑
在开发程序中我们都会遇到要处理物理返回键是后退还是退出的问题
论坛中也已经明确的说明了该怎么处理,见:
http://docs.wex5.com/wex5-app-question-list-2003/
调用方法也有例子,在淘宝和网易的首页中都有调用返回键的处理。
大体思路就是:
通过获取首页当中的一个组件标识(可以是组件名称),也可以是组件当中的一个属性,
反正就是唯一的一个标识。
通过判断这个标识是不是你要的标识来确定是不是在首页点击了返回按键,是的话就退出,不是就后退
案例中的回退判断:判断组件contents2是否在当前活动中
- shellImpl.useDefaultExitHandler = false;
- CommonUtils.attachDoubleClickExitApp(function() {
-
- var isHomePage = shellImpl.pagesComp.contents[0].innerContainer.getInnerModel().comp('contents2').getActiveIndex() == 0;
- if (shellImpl.pagesComp.getActiveIndex() === 0 && isHomePage) {
- return true;
- }
- return false;
- });<span style="line-height: 1.5;"> </span>
复制代码 我的应用中所用的判断:我所使用的是baseURI这个属性中是否含有main来判断是否是主页
- isHomePage = window.location.hash.indexOf("!main") > 0;
复制代码 我的应用中所用的判断:我所使用的是baseURI这个属性中是否含有"!main"来判断是否是主页
shellImpl.useDefaultExitHandler = false;
CommonUtils.attachDoubleClickExitApp(function() {
var isHomePage =false;
isHomePage = window.location.hash.indexOf("!main") > 0; ;
if (isHomePage) {
return true;
}
return false;
});
center的由来是从pageMappings来的;center代表跳转到主页
var shellImpl = new ShellImpl(this, {
contentsXid : "pages",
wingXid : "wing",
pageMappings : {
"main" : {
url : require.toUrl('$UI/nqcj/main/main.w')
},
"personal" : {
url : require.toUrl('./personal.w')
}
}
附:JS获取当前页面的方法
1,设置或获取对象指定的文件名或路径。
alert(window.location.pathname)
2,设置或获取整个 URL 为字符串。
alert(window.location.href);
3,设置或获取与 URL 关联的端口号码。
alert(window.location.port)
4,设置或获取 URL 的协议部分。
alert(window.location.protocol)
5,设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash)
6,设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host)
7,设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search)
8,获取变量的值(截取等号后面的部分)
var url = window.location.search;
// alert(url.length);
// alert(url.lastIndexOf('='));
var loc = url.substring(url.lastIndexOf('=')+1, url.length);
9,用来得到当前网页的域名
var domain = document.domain;
|
|