【问题标题】:How to detect a specific console output?如何检测特定的控制台输出?
【发布时间】:2021-04-10 04:42:16
【问题描述】:
<script src="https://cdnjs.cloudflare.com/ajax/libs/UAParser.js/0.7.19/ua-parser.min.js"></script>

<script>
    var ua = new UAParser();
    var result = ua.getResult();

    console.log(result.device);


</script>

此代码获取用户使用的设备的名称并将其显示在控制台中。如何根据使用的设备使用该信息显示不同的网页?如果设备不是移动设备,它不会在控制台中显示任何内容。当它是移动设备时,我只希望它转到不同的页面。我需要这个,以便在用户使用移动设备时显示我的网站的移动版本。

(代码不是我从这里得到的:https://codewithmark.com/mobile-detect

【问题讨论】:

    标签: console console.log device-detection


    【解决方案1】:
    if (result.device.model != undefined){document.location="https://google.com";}
    

    【讨论】:

    • 请分享更多细节。这段代码和控制台有什么关系?
    猜你喜欢
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    相关资源
    最近更新 更多