在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sebarmeli/JS-Redirection-Mobile-Site开源软件地址(OpenSource Url):https://github.com/sebarmeli/JS-Redirection-Mobile-Site开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):JS Mobile Redirectionredirection_mobile.js is a utility script that covers a basic scenario for redirecting your website to a mobile verison through JavaScript. It also covers the scenario where a user wants to access the Desktop version of the site from a mobile device (sometimes the desktop version has more functionality). The script handles tablets too, you can choose to redirect user to a mobile site or to a specific site for tablets (7'' or 10''). Getting startedThe script needs to be put in the desktop version of the site. The script sniffs the User-Agent string and it decides if the redirection needs to happen. If the user decides to view the 'desktop' version from a mobile site, the user is kept on that version for the whole session. (sessionStorage object has been used). There is a fallback for old browsers that don't support sessionStorage, and a cookie is used. The cookie expiries in one hour or you configure the expiry time. To use this function, you need to import the "redirection_mobile.js" in your page and call the SA.redirection_mobile() function. <!doctype html>
<html>
<head>
<script src="redirection-mobile.js"></script>
<script>
SA.redirection_mobile();
</script>
</head> ConfigThe function accepts few configurations:
ExamplesIf you want to redirect the user to "http://mobile.domain.com" from "http://domain.com": SA.redirection_mobile ({
redirection_param : "mobile_redirection",
mobile_prefix : "mobile",
cookie_hours : "2"
}); If you want to redirect the user to "https://whatever.com/example": SA.redirection_mobile ({
mobile_url : "whatever.com/example",
mobile_prefix : "https"
}); If you want to redirect the user to "https://whatever.com/example" even when using an Ipad or a generic tablet: SA.redirection_mobile ({
tablet_redirection : "true",
mobile_url : "whatever.com/example",
mobile_prefix : "https"
}); If you want to avoid the redirection to happen from a callback, this is the invocation you need: SA.redirection_mobile ({
beforeredirection_callback : (function(){alert("!"); return false;})
}); If you want to redirect the user to two different URLs depending on the device the user is using (mobile or tablet): SA.redirection_mobile ({
mobile_url : "mobile.whatever.com",
tablet_host : "tablet.whatever.com",
}); If the user accesses to "whatever.com/page1" and you want to redirect him to "mobile.whatever.com/page1": SA.redirection_mobile ({
mobile_prefix : "mobile",
keep_path : true,
keep_query : true
}); What is 'redirection-mobile-self.js'?Alternatively you can use "redirection_mobile_self.js", that is an anonyimous self-executing function using the default values for the different properties:
It doesn't need any configuration or any invocation, so you just need to drop "it "redirection_mobile_self.js" on your webserver and call the script from your HTML. <!doctype html>
<html>
<head>
<script src="redirection_mobile_self.js"></script>
</head> I also created 'redirection-mobile-testable.js' that is just a copy from "redirection_mobile.js", but it's using few arguments such as "document", "window", "navigator" for testing purpose. Testing / Building the pluginAfter getting node and npm, install grunt and grunt-jasmine-runner.
You can run Jasmine specs through phantomjs with :
If you don't have phantomjs, please download it from here You can run JSHint, Jasmine specs and minification tool simply launching: LicenceCopyright (c) 2011-2012 Sebastiano Armeli-Battana Licensed under the MIT license. (https://github.com/sebarmeli/JS-Redirection-Mobile-Site/blob/master/MIT-LICENSE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论