简体   繁体   English

将JavaScript检测与MVC4显示模式集成的最佳方法是什么?

[英]What is the best way to integrate JavaScript detection with MVC4 display modes?

I'm working on an existing MVC project and I'm currently looking at using the display modes features. 我正在开发一个现有的MVC项目,目前正在考虑使用显示模式功能。 I'm hoping that the final application will be able to return three different types of view. 我希望最终的应用程序将能够返回三种不同类型的视图。

  • Mobile - Mobile phones, IE6/7 , 手机- 手机,IE6 / 7
  • Non-JavaScript browsers - Tablet 非JavaScript浏览器- 平板电脑
  • Tablet browsers Desktop - Desktop browsers 平板电脑浏览器桌面- 桌面浏览器

Everything is simple enough except the JavaScript detection. 除了JavaScript检测之外,其他一切都非常简单。

Currently it's a desktop application that gracefully degrades. 当前,它是一个可以正常降级的桌面应用程序。 This is great but takes a lot of time to support Non-JavaScript users (which is only 2% of our audience and most of these are probably bots). 这很棒,但是要花费很多时间来支持非JavaScript用户(这仅占我们受众的2%,其中大多数可能是机器人)。 So I want to give the non-JavaScript users the basic mobile version of the site which should be less effort to support. 因此,我想为非JavaScript用户提供该网站的基本移动版本,而该版本应该花费较少的精力来支持。

I understand that something will have to be rendered client side and then a redirect. 我了解必须先向客户端呈现某些内容,然后再进行重定向。 But what is the best way to do this? 但是最好的方法是什么? Do I default to mobile and redirect with JavaScript or do I do something with <noscript> tags? 我是否默认使用移动设备并使用JavaScript进行重定向,还是使用<noscript>标签进行某些操作?

Thanks for any help 谢谢你的帮助

In your scenario using <noscript> tags in combination with a meta refresh is probably what you want: 在您的方案中,将<noscript>标记与元刷新结合使用可能是您想要的:

<head>

  <noscript>
    <meta http-equiv="refresh" content="0; url=http://example.com/mobile" />
  </noscript>

</head>

I wouldn't recommend doing it the other way around (first loading the mobile and redirect with JavaScript) because as you said the non-JS users are only 2% and that would just add unnecessary overhead for all your other users. 我不建议您采用其他方法(首先加载移动设备并使用JavaScript重定向),因为正如您所说的那样,非JS用户仅占2%,这只会为所有其他用户增加不必要的开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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