Touchmove不能与Google apps scripts html服务一起工作
Touchmove doesn't work with Google apps scripts html service
我试图让touchmove
事件注册使用谷歌应用程序脚本html服务编写的一个简单的web应用程序,这样我就可以使简单的web应用程序在iPad上以及在桌面上运行。
我所做的就是首先加载一个网页,它工作如预期:
function doGet() {
return HtmlService.createHtmlOutputFromFile('test page');
}
然后我在html页面上创建了一个简单的画布:
<html>
<canvas id="canvas" width="200" height="200" style="border:1px solid #000000;">
</canvas>
<script>
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
ctx.font = "bold 12px sans-serif";
ctx.fillStyle="black";
ctx.fillText("TEST",50,50);
canvas.addEventListener("touchmove",testme,false);
function testme(e) {
e.preventDefault();
alert("testme");
}
</script>
</html>
这只是我尝试过的最新版本。绑定click
或mousedown
或mousemove
在本例中在桌面上都可以正常工作。然而,尝试touchstart
或touchmove
在iPad上不做任何事情。我在iPad上用Chrome和Safari进行了测试。
我也试过添加一些东西,比如:
document.addEventListener("touchmove",doPreventDefault,false);
有一个简单的函数调用preventDefault()
,但这也没有帮助。
我做错了什么,或者我必须做一些不同的东西,因为它是谷歌应用程序脚本html服务?
我现在已经尝试使用jQuery(只是阅读如何做到这一点),但它似乎仍然不能在iPad上正常工作:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<p>Test</p>
<br><br>
</body>
<canvas id="canvas" width="200" height="200" style="border:1px solid #000000;">
</canvas>
<script>
$(document).ready(function() {
$("#canvas").bind('touchstart',function(e) {
alert("Hello world!");
});
$("p").mousedown(stuff);
$('#canvas').touchmove(onMove);
});
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
ctx.font = "bold 12px sans-serif";
ctx.fillStyle="black";
ctx.fillText("TEST",50,50);
function onMove(e) {
alert("testing");
}
function stuff(e) {
alert("Stuff");
}
</script>
</html>
mousedown
事件工作得很好,如果事件与触摸一起工作-事实上,mousedown
和mouseup
似乎与iPad上的触摸相关。但是mousemove
不起作用,touchmove
或touchstart
或touchend
也不起作用。我已经尝试了bind和更直接的方法,如上面所示。
有什么我做错了让这个工作吗?
您可以在Caja问题跟踪器上添加功能请求,将这些事件列入白名单。
阅读htmlservice文档。你不能操作dom,除非你使用caja兼容的方式,如jquery。
相关文章:
- AngularJS-需要在index.html页面中访问来自服务的数据
- 从简单的html页面调用实时Web服务.
- 谷歌应用程序脚本html服务和加载谷歌地图javascript api V3
- JQuery-HTML到PDF没有'无法在IE中工作(来自C#asmx Web服务)
- 在HTML服务中验证电子表格
- 将JSON从索引操作服务到公用文件夹中的index.html
- HTML服务为图像分配URL
- 如何在URL中不指定.html、.json的情况下配置web.xml来服务任何请求
- 使用ajax将数据发布到asmx web服务并使用javascript函数在html页面中编写响应时出错
- 在异步内部函数返回 [UI-路由器和 HTML 服务] 之后返回外部 fn
- 从谷歌电子表格检索单元格日期到HTML服务
- .gs/.Google Apps 脚本作为 Web 应用,使用表单元素、HTML 服务和电子表格
- 如何从图表谷歌脚本的电子表格中检索数据.(使用 HTML 服务)
- 使用谷歌HTML服务上传文件时验证HTML输入字段
- 谷歌应用程序脚本的新功能'的HTML服务
- 谷歌应用程序脚本HTML服务-Can't get Keypress to work
- 表日期列格式化与谷歌应用程序脚本html服务
- 表单验证使用HTML服务在谷歌应用脚本
- Touchmove不能与Google apps scripts html服务一起工作
- 对象引用在HTML服务中丢失