Html MVC和jQuery Mobile中基于设备宽度和高度的重定向
当设备以640px以下的宽度和960px以下的高度访问网站时,我需要将MVC应用程序从www.company.com重定向到www.company.com/mobile 我更喜欢在服务器中检测请求的第一个联系人,这样我就不需要加载布局并在客户端进行检测(如果我没有错的话)Html MVC和jQuery Mobile中基于设备宽度和高度的重定向,html,css,asp.net-mvc,jquery-mobile,Html,Css,Asp.net Mvc,Jquery Mobile,当设备以640px以下的宽度和960px以下的高度访问网站时,我需要将MVC应用程序从www.company.com重定向到www.company.com/mobile 我更喜欢在服务器中检测请求的第一个联系人,这样我就不需要加载布局并在客户端进行检测(如果我没有错的话) 谢谢。在研究了获得宽度和高度的不同方法后,我决定使用此方法: <script> var width = window.innerWidth || document.body.clientWi
谢谢。在研究了获得宽度和高度的不同方法后,我决定使用此方法:
<script>
var width = window.innerWidth || document.body.clientWidth;
var height = window.innerHeight || document.body.clientHeight;
if (width < 960 || height < 620)
{
// screen is too small, redirect to mobile version
location.href = '/Mobile/index.html';
}
</script>
var width=window.innerWidth | | document.body.clientWidth;
var height=window.innerHeight | | document.body.clientHeight;
如果(宽度<960 | |高度<620)
{
//屏幕太小,重定向到移动版本
location.href='/Mobile/index.html';
}
另一种选择是:
void Session_Start(object sender, EventArgs e)
{
// Redirect mobile users to the mobile home page
int wight = Request.Browser.ScreenPixelsWidth;
int height = Request.Browser.ScreenPixelsHeight;
HttpRequest httpRequest = HttpContext.Current.Request;
if (httpRequest.Browser.IsMobileDevice)
{
string path = httpRequest.Url.PathAndQuery;
bool isOnMobilePage = path.StartsWith("/Mobile/", StringComparison.OrdinalIgnoreCase);
if (!isOnMobilePage)
{
if (wight < 720 && height < 1280)
{
string redirectTo = "~/Mobile/Index.html";
HttpContext.Current.Response.Redirect(redirectTo);
}
}
}
}
void会话\u启动(对象发送方,事件参数e)
{
//将移动用户重定向到移动主页
int-wight=Request.Browser.ScreenPixelsWidth;
int height=Request.Browser.screen像素高度;
HttpRequest HttpRequest=HttpContext.Current.Request;
if(httpRequest.Browser.IsMobileDevice)
{
字符串路径=httpRequest.Url.PathAndQuery;
bool isOnMobilePage=path.StartsWith(“/Mobile/”,StringComparison.OrdinalIgnoreCase);
如果(!isOnMobilePage)
{
如果(高度<720和高度<1280)
{
字符串重定向到=“~/Mobile/Index.html”;
HttpContext.Current.Response.Redirect(重定向到);
}
}
}
}
但是,获取设备的宽度和高度是不公平的。您见过这个:[带jQuery和MVC的可切换桌面/移动站点])嗨,谢谢!是的,我看到了,但他没有谈到宽度检测或重定向,这是我需要的。移动版本是静态的,不与MVC应用程序集成,用于将来的phonegap集成。