jquery - How can I automatically disable AJAX on local links which do not have a mobile-suitable view? -
i using jquery mobile build mobile version of existing asp.net mvc3 site.
the way doing detecting in controllers if page being requested mobile or not , providing mobile-suited mvc view if there 1 , providing standard view if there isn't.
the problem having links pages not have suitable view still ajaxed page jquery-mobile, messing layout. know can disable functionality on link-by-link basis using data-ajax="false", not have control on each link cms-based site there nothing stop user linking page within site not have mobile view.
what hoping maybe include attribute in base view of desktop version of site jquery mobile pick when attempts ajax load page, rejecting , reloading link without ajax. possible?
i'd suggest rendering combination of localised js , viewbag properties handle problem per page, otherwise you'll end scenario you'll have apply 'data-ajax="false"' everywhere, isn't pretty.
aside controller code user agent detection populate "viewbag.ismobiledevice" property, following may out:
<script type="text/javascript"> $( document ).bind( "mobileinit", function( event, data ){ if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appversion) && @viewbag.ismobiledevice) { $.mobile.ajaxenabled = false; } }); </script> please note i'm using iphone/ipad/ipod example, use in it's place depending on requirements. i'd 51degrees.mobi inspiration on mobile detection.
i hope helps out or @ least points in right direction.
Comments
Post a Comment