Touchmove不适用于谷歌应用脚​​本html服务

时间:2013-04-19 05:17:13

标签: ipad web-applications javascript-events google-apps-script touchmove

我正试图通过使用谷歌应用程序脚本html服务编写的简单网络应用程序来注册touchmove事件,以便我可以制作在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()的简单函数,但这也无济于事。

我做错了什么,或者我必须做些不同的事情,因为它是google apps脚本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和更直接的,如上所示。

有什么我做错了让这项工作?

2 个答案:

答案 0 :(得分:1)

您可以添加功能请求on the Caja issue tracker以将这些事件列入白名单。他们目前不在白名单上。

答案 1 :(得分:0)

阅读htmlservice文档。 你不能操纵dom,除非你使用像jquery那样的caja兼容方式。