navigator.device is undefined



我有一个脚本,我创建捕捉相机流,但我得到一个未定义的,当我尝试做"navigator.device"。下面是一些示例代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <body>
        <head><meta charset="UTF-8"></head>
        <button onclick="myTest();"> TEST</button>
        <p id="capture-result"><i>&lt;results go here&gt;</i></p>
        <script>
            var resdev = document.getElementById('capture-result');
            function myTest(){
                resdev.innerHTML = "<br>&lt;Looking...&gt;<hr/>";
                var str = "";
                var x;
                checkResults("1", (navigator                == undefined));
                checkResults("2", (navigator.device         == undefined));
                checkResults("3", (navigator.device.capture == undefined));
            }
            function checkResults(name, truefalse) {
                resdev.innerHTML += name + "-";
                resdev.innerHTML += (truefalse) ? "UNDEFINED" : "OK";
                resdev.innerHTML += "<br>";
            }     
        </script>
    </body>
</html>

我在'navigator.device'的checkResults上得到'undefined'错误

当我谷歌"navigator.device"我得到,除其他外,PhoneGap API文档。

还有一个(老的/未回答的)SO问题Phonegap navigator.device issue android.

你需要PhoneGap来做你想做的事情。


编辑

对于许多事情,你可以使用功能检测和加载phonegap,只有当浏览器本身不支持它。

基本概念是测试,如if (navigator.device == udefined) { doSomethingToLoad(phonegap); }

我个人使用Modernizr来完成这类任务。

相关内容

最新更新