简体   繁体   English

Touchmove 不适用于 Google 应用程序脚本 html 服务

[英]Touchmove doesn't work with Google apps scripts html service

I'm trying to get touchmove events to register with a simple web app written using Google apps scripts html service so that I can make simple web apps that function on the iPad as well as on a desktop.我试图让touchmove事件注册一个使用 Google 应用程序脚本 html 服务编写的简单网络应用程序,以便我可以制作在 iPad 和桌面上运行的简单网络应用程序。

All I do is first load a web page, which works as expected:我所做的就是首先加载一个网页,它按预期工作:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('test page');
}

Then I created a simple canvas on the html 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>

This is just the latest variant I have tried.这只是我尝试过的最新变体。 Binding click or mousedown or mousemove all work fine in this example on a desktop.在此示例中,绑定clickmousedownmousemove在桌面上都可以正常工作。 However, trying with touchstart or touchmove don't do anything on an iPad.但是,尝试使用touchstarttouchmove在 iPad 上没有任何作用。 I have tested with both Chrome and Safari on the iPad.我已经在 iPad 上对 Chrome 和 Safari 进行了测试。

I have also tried adding something like:我也尝试添加类似的东西:

document.addEventListener("touchmove",doPreventDefault,false);

And have a simple function that calls preventDefault() , but that didn't help either.并有一个调用preventDefault()的简单函数,但这也无济于事。

Am I doing something wrong, or do I have to do something different because it is google apps script html service?我做错了什么,还是我必须做一些不同的事情,因为它是谷歌应用程序脚本 html 服务?

I have now tried with jQuery (just read up on how to do it) but it still doesn't seem to work right on the iPad:我现在已经尝试过 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>

The mousedown event works fine, and it event works with a touch - in fact, it seems mousedown and mouseup correlate work with touches on the iPad. mousedown事件工作正常,并且它的事件与触摸一起工作 - 事实上, mousedownmouseup似乎与 iPad 上的触摸相关联。 But mousemove doesn't work and neither does touchmove or touchstart or touchend .但是mousemove不起作用, touchmovetouchstarttouchend I have tried with bind and more directly as seen above.如上所示,我尝试使用 bind 和更直接的方法。

Is there something I'm doing wrong to make this work?有什么我做错了使这项工作?

You can add a feature request on the Caja issue tracker to whitelist those events.您可以在 Caja 问题跟踪器上添加功能请求以将这些事件列入白名单。 They currently are not on the whitelist.他们目前不在白名单上。

Read the htmlservice docs.阅读 htmlservice 文档。 You cant manipulate the dom unless you use a caja-compatible way like jquery.除非您使用像 jquery 这样的与 caja 兼容的方式,否则您无法操纵 dom。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM