简体   繁体   中英

Sencha Touch how to load custom CSS , JS if user is using PC or Tablet or SmarthPhone?

How to setup page so when user is using Pc(Safari/Chrome/Firefox), user gets "normal" web page, but when he is using "ipad" to view the same URL, he gets Sencha Touch(css,js) files to his browser? JavaScript Browser Detection,navigator? Or Sencha has native solution for this? I know about Ext.env.Browser but user can have Safari on PC and IPAD? Any ideas? Thanks!

I think the best and the cleanest solution is to add this functionality on the server side. Check the user-agent request header to decide which files to send. You can also redirect to different sub domain, eg to m.example.com. But if you want to do it with sencha then read this article: http://www.sencha.com/learn/idiomatic-layouts-with-sencha-touch

Example:

<script type="text/javascript">

    var isiPad  = navigator.userAgent.match(/iPad/i) != null;   
    var isiPhone    = navigator.userAgent.match(/iPhone/i) != null; 

        if(isiPad){
            alert("Ipad");
            //window.location = "http://www.google.com/iPad/"
        }if(isiPhone){
            alert("Iphone");
            //window.location = "http://www.google.com/iPhone/"
        }else{
            window.location = "http://www.google.com"
        }

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM