【问题标题】:Redirection to Mobile Webpage重定向到移动网页
【发布时间】:2014-09-14 15:01:36
【问题描述】:

我有一个网页可以检测屏幕宽度,然后将移动用户重定向到由 jQuery Mobile 制作的移动 html。但这样一来,一些三星手机用户似乎出现了错误,用户没有查看桌面站点的选项。我目前的代码是这样的:

 <script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobilehome.html";
}
//-->
    </script>
    <script language=javascript>
<!--
        if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){
            window.location = "http://viewplus.url.ph/mobilehome.html";}


    </script>

我想要一个可以将用户重定向到移动网页的网站,但我希望他们也可以选择查看桌面页面。 (就像“桌面”按钮)我知道这是可能的,但我不知道怎么做!请帮忙!

【问题讨论】:

    标签: javascript jquery html jquery-mobile mobile


    【解决方案1】:

    尝试根据设备的分辨率或屏幕尺寸来确定设备是否是移动设备是个坏主意,因为它们可能会有很大差异。

    Here 是一个很棒的插件,它为您提供了一个对象,您可以轻松检查用户的设备是否是移动设备。只需在你的代码中包含这个插件,之后你就可以做

    if( isMobile.any ) window.location = "mobilehome.html";
    

    还有很多其他选项可以针对特定设备。

    【讨论】:

    • 不,没有说插件需要 jQuery 才能工作。你确定你正确地包含了插件吗?
    • 另外,请参阅我的答案的更新,您应该使用 window 对象来重定向页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    相关资源
    最近更新 更多