不能简单地强调在使用HtmlService的独立Google App中的文本输入? [英] Cannot simply force focus on text input in stand-alone Google App using HtmlService?

查看:139
本文介绍了不能简单地强调在使用HtmlService的独立Google App中的文本输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面是一个例子,其中focus()应该做到这一点,但它不!为什么?

Code.gs:

$ p $ 函数doGet(e) {

返回HtmlService.createHtmlOutputFromFile('myFile');

$ b

myFile.html:

 < input type =textid =newonchange =adding(this)/> 

< div id =data>< / div>

< script>

document.getElementById('new')。focus();

函数添加(a){

document.getElementById('data')。innerHTML + = a.value;

a.value ='';
}

< / script>

我也尝试过将focus()放在它自己的函数中, onload调用该函数。

有一个按钮,它的onclick调用了这个函数,所以focus()最终会变成活动的。是否有其他事件可以用来触发它?



我正在使用Chromebook。这可能是问题吗?

解决方案

这是Caja中的一个有意的安全决定。某些功能(网络上)容易遭受严重的恶意滥用,例如submit()和focus(),只能在用户启动的事件(如点击按钮)的情况下执行。


I want to script a click on an input box.

Here is an example where the focus() should do just that, but it doesn't! Why?

Code.gs:

function doGet(e) {

  return HtmlService.createHtmlOutputFromFile('myFile');

}  

myFile.html:

<input type="text" id="new" onchange="adding(this)"/>

<div id="data"></div>

<script>

   document.getElementById('new').focus();

   function adding(a){

      document.getElementById('data').innerHTML += a.value;

      a.value = '';
   }

</script>

I have also tried without success putting the focus() in its own function and having a body element whose onload calls that function.

What DOES work is having a button whose onclick calls that function, so focus() does eventually become active. Is there some other event I can use to trigger it?

I am using a Chromebook. Could that be the problem?

解决方案

This is an intentional security decision in Caja. Certain functions that are prone (across the web) to serious malicious misuse, such as submit() and focus(), can only be executed while in the context of a user-initiated event (such as a button click).

这篇关于不能简单地强调在使用HtmlService的独立Google App中的文本输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆