为了将 Canvas 图像保存到画廊,我尝试通过在phonegap中创建插件以及下面的一段javascript代码,但是单击按钮后我得到“Uncaught TypeError: Cannot read property 'version' of undefined at file:///android_asset/www/index.html:18"
代码
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="SavePhotoPlugin.js"></script>
<link rel="stylesheet" href="index.css" />
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var element = document.getElementById('myCanvas');
}
function share() {
var canvas = document.getElementById("myCanvas");
window.savephotoplugin(canvas,"image/png",device.version,function(val){
//returns you the saved path in val
alert("Photo Saved: " + val);
});
}
</script>
</head>
<body>
<div >
<IMG SRC="loadin.png" ALT="some text" WIDTH=100 HEIGHT=100>
<button class="button" id="myCanvas" onclick="share()">SAVE </button>
</div>
我尝试使用cordova 2.2、2.9,所有版本都保持不变,在 2.3 版本设备上进行了测试。这是cordova版本设备的问题,还是其他问题,请大家指出错误。
最佳答案
最新版本的 jQuery 不再支持浏览器检测。如今,大多数人推荐功能检测而不是浏览器检测。
您需要恢复到 1.9 之前的 jQuery 库,使用 jQuery 迁移插件,或者将引用浏览器版本的 JavaScript 代码修改为不同的版本,例如 Modernizr。
关于javascript - 未捕获的类型错误 : Cannot read property 'version' of undefined at file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19271733/