web*_*ers 13 javascript jquery redirect
我宣传一家公司,基本上我是一个会员.我想将移动浏览器重定向到我的联盟网站的移动版本.我想用屏幕分辨率来做这件事.基本上,如果屏幕分辨率低于800 x 600,则客人使用手机的可能性很大.
这是一个很好的想法吗?
这是代码:
if ( (screen.width < 800) && (screen.height < 600) ) {
window.location = 'mobilesite';
}
Run Code Online (Sandbox Code Playgroud)
泰!
gha*_*yes 17
检查浏览器的用户代理通常更安全,因为您将知道它们是否在Android,iPhone,iPad,iPod,诺基亚......上,并且您可以更灵活地从那里引导用户.我使用以下Javascript(可能是从其他来源借来的):
var isMobile = function() {
console.log("Navigator: " + navigator.userAgent);
return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
};
Run Code Online (Sandbox Code Playgroud)
屏幕宽度是一种可用的技术.我经常看到这与CSS媒体查询一起使用,根据"设备宽度"和"设备高度"更改内容.例如
@media only screen and (max-device-width: 480px) {
/* For small devices, just CSS */
}
Run Code Online (Sandbox Code Playgroud)
要使用屏幕宽度/高度的技术,这来自Mozilla文档:
// crude way to check that the screen is at 1024x768
if (window.screen.width < 1000) {
// resolution is below 10 x 7
window.location = 'm.mysite.com'; //for example
}
Run Code Online (Sandbox Code Playgroud)
一些警告:
随着移动设备在渲染和交互方面变得更好,请注意,用户可能更喜欢看到原始网站而不是移动网站.尝试提供一个返回主站点的方法.
希望这一切都可以帮助您解决问题!
| 归档时间: |
|
| 查看次数: |
28374 次 |
| 最近记录: |