Jquery mobile 如何在JQuery Mobile中绕过登录屏幕?
我有一个FB.getLoginStatus函数,如果用户已经授权了应用程序,它可以绕过登录函数:Jquery mobile 如何在JQuery Mobile中绕过登录屏幕?,jquery-mobile,Jquery Mobile,我有一个FB.getLoginStatus函数,如果用户已经授权了应用程序,它可以绕过登录函数: FB.getLoginStatus(function(response) { if (response.status === 'connected') { userID = response.authResponse.userID; accessToken = response.authResponse.accessToken;
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
userID = response.authResponse.userID;
accessToken = response.authResponse.accessToken;
$.mobile.pageContainer.pagecontainer('change' , '#homepage');
navigator.geolocation.getCurrentPosition(onSuccess, onError);
} else if (response.status === 'not_authorized') {
$.mobile.pageContainer.pagecontainer('change' , '#login');
} else {
$.mobile.pageContainer.pagecontainer('change' , '#login');
}
});
它的工作原理是检查登录状态,但在跳转到主屏幕之前,它会快速闪烁登录屏幕。如果用户已连接,是否有办法完全避免闪烁登录屏幕,只加载主屏幕?是的,有一个可行的解决方案:
$(document).on('pagebeforechange', function(e, data){
var to = data.toPage,
from = data.options.fromPage;
if (typeof to === 'string') {
var u = $.mobile.path.parseUrl(to);
to = u.hash || '#' + u.pathname.substring(1);
if (from) from = '#' + from.attr('id');
if (from === '#index' && to === '#second') {
alert('Can not transition from #index to #second!');
e.preventDefault();
e.stopPropagation();
// remove active status on a button, if transition was triggered with a button
$.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active ui-shadow').css({'box-shadow':'0 0 0 #3388CC'});
}
}
});
这里需要做的是向此行添加另一层检查:
if (from === '#index' && to === '#second') {
您只需检查用户是否已通过Facebook授权,并使用函数changePage()以编程方式重定向他
阅读更多关于它的信息
更新
我忘了,这个例子在您的情况下可能不起作用,因为如果您在开始检查它,您将没有目标页面,因为您在这里确定哪个页面是第一个:登录页面还是主页
在这种情况下,此代码将帮助您:
$(document).on('pagebeforechange', function(e, data){
var to = data.toPage;
if (typeof to === 'string') {
var u = $.mobile.path.parseUrl(to);
to = u.hash || '#' + u.pathname.substring(1);
if (to === '#second') {
alert('Can not transition the page #second!');
e.preventDefault();
e.stopPropagation();
// remove active status on a button, if transition was triggered with a button
$.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active ui-shadow').css({'box-shadow':'0 0 0 #3388CC'});
}
}
});
我只需要将{transition:'none}添加到$.mobile.pageContainer操作中。谢谢你的解释,但我相信它更倾向于阻止导航到某个页面,不幸的是,它并不能解决我的情况。