English 中文(简体)
如何根据装置(如桌面、移动等)列入/不包括外部的 Java字档案?
原标题:How to include/not include external Javascript files according on the device (e.g. Desktop, mobile, etc?
  • 时间:2011-10-22 11:18:35
  •  标签:
  • javascript

我的头脑(我知道某种坏的做法):

?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="<?php bloginfo( template_directory ); ?>/js/cleditor/jquery.cleditor.min.js"></script>
<script type="text/javascript" src="<?php bloginfo( template_directory ); ?>/js/jquery.expander.js"></script>
<script type="text/javascript" src="<?php bloginfo( template_directory ); ?>/js/jquery.qtip-1.0.0-rc3.min.js"></script>
<script type="text/javascript" src="<?php bloginfo( template_directory ); ?>/js/custom.js"></script>

</head>

我不想包括:

<script type="text/javascript" src="<?php bloginfo( template_directory ); ?>/js/cleditor/jquery.cleditor.min.js"></script>

转载于移动电话和表格。 任何关于如何实现这一目标的想法?

最佳回答

据我所知,没有100%的安全解决办法来检测移动装置:

  • UA的松散取决于移动式紫外线清单。 这些清单目前相当长,但可以处理未来/冲突装置。

  • 当标准像“机动/静态”一样广泛时,对特征的探测非常困难。 筛选解决办法在非机动性和机动性之间没有差别(检查新的谷歌电话,比净书更重),感触支持可在传统的丝网中找到。

我将选择一个基于WURFL的UNA松散解决办法,而没有再方向:如果不是流动的话,则重复你的文字,如果是流动的话,则不重复。

但流动和非流动世界正在合并。 你们应使用特征探测,检查你想要使用的具体特征,无论是移动装置还是非机动装置。

http://detectmobilebrowsers.mobi/“rel=“nofollow”http://detectmobilebrowsers.mobi/ a. 简单地在综合体内传播

问题回答

I dont know how to do this but this is the solution: Use javascript to decide if its a mobile accessing your site or a computer...

之后,如果其移动式,则将用户转移到移动网页上而不采用联合材料法典......

如果不改用计算机网页......

You ll have to create separate pages to do that...

I m sure there may be other ways to do this too...

rel=“nofollow noretinger”>https://github.com/BoilerplateMVC/Marionette-Require-Boilerplate/blob/master/public/index.html

包括不同的生产档案和检测器ENV

 // Mobile/Desktop Detection script
            (function(ua, w, d, undefined) {

                // App Environment
                // ---------------
                //  Tip: Set to true to turn on "production" mode
                var production = true,
                        filesToLoad,
                //BoilerplateMVC Helper Methods
                        boilerplateMVC = {
                            loadCSS: function(url, callback) {
                                var link = d.createElement("link");
                                link.type = "text/css";
                                link.rel = "stylesheet";
                                link.href = url;
                                d.getElementsByTagName("head")[0].appendChild(link);
                                if(callback) {
                                    callback();
                                }
                            },
                            loadJS: function(file, callback) {
                                var script = d.createElement("script");
                                script.type = "text/javascript";
                                if (script.readyState) {  // IE
                                    script.onreadystatechange = function() {
                                        if (script.readyState == "loaded" || script.readyState == "complete") {
                                            script.onreadystatechange = null;
                                            callback();
                                        }
                                    };
                                } else {  // Other Browsers
                                    script.onload = function() {
                                        callback();
                                    };
                                }
                                if(((typeof file).toLowerCase()) === "object" && file["data-main"] !== undefined) {
                                    script.setAttribute("data-main", file["data-main"]);
                                    script.async = true;
                                    script.src = file.src;
                                } else {
                                    script.src = file;
                                }
                                d.getElementsByTagName("head")[0].appendChild(script);
                            },
                            loadFiles: function(production, obj, callback) {
                                var self = this;
                                if(production) {
                                    // Loads the production CSS file(s)
                                    self.loadCSS(obj["prod-css"], function() {
                                        // If there are production JavaScript files to load
                                        if(obj["prod-js"]) {
                                            // Loads the correct initialization file (which includes Almond.js)
                                            self.loadJS(obj["prod-js"], callback);
                                        }
                                    });
                                } else {
                                    // Loads the development CSS file(s)
                                    self.loadCSS(obj["dev-css"], function() {
                                        // If there are development Javascript files to load
                                        if(obj["dev-js"]) {
                                            // Loads Require.js and tells Require.js to find the correct intialization file
                                            self.loadJS(obj["dev-js"], callback);
                                        }
                                    });
                                }
                            }
                        };

                // Mobile/Tablet Logic
                if((/iPhone|iPod|iPad|Android|BlackBerry|Opera Mini|IEMobile/).test(ua)) {

                    // Mobile/Tablet CSS and JavaScript files to load
                    filesToLoad = {
                        // CSS file that is loaded when in development mode
                        "dev-css": "css/mobile.css",
                        // CSS file that is loaded when in production mode
                        "prod-css": "css/mobile.min.css",
                        // Require.js configuration file that is loaded when in development mode
                        "dev-js": { "data-main": "js/app/config/config.js", "src": "js/libs/require.js" },
                        // JavaScript initialization file that is also loaded when in development mode
                        "dev-init": "js/app/init/MobileInit.js",
                        // JavaScript file that is loaded when in production mode
                        "prod-init": "js/app/init/MobileInit.min.js",
                        "prod-js": { "data-main": "js/app/config/config.js", "src": "js/libs/require.js" }
                    };

                }

                // Desktop Logic
                else {

                    // Desktop CSS and JavaScript files to load
                    filesToLoad = {
                        // CSS file that is loaded when in development mode
                        "dev-css": "css/desktop.css",
                        // CSS file that is loaded when in production mode
                        "prod-css": "css/desktop.min.css",
                        // Require.js configuration file that is also loaded when in development mode
                        "dev-js": { "data-main": "js/app/config/config.js", "src": "js/libs/require.js" },
                        // JavaScript initialization file that is loaded when in development mode
                        "dev-init": "js/app/init/DesktopInit.js",
                        // JavaScript file that is loaded when in production mode
                        "prod-init": "js/app/init/DesktopInit.min.js",
                        "prod-js": { "data-main": "js/app/config/config.js", "src": "js/libs/require.js" }
                    };

                }

                boilerplateMVC.loadFiles(production, filesToLoad, function() {
                    if(!production && window.require) {
                        require([filesToLoad["dev-init"]]);
                    } else if ( production ) {
                        require([filesToLoad["prod-init"]])
                    }
                });

            })(navigator.userAgent || navigator.vendor || window.opera, window, document);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签