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).
来源:https://stackoverflow.com/questions/15387457/cannot-simply-force-focus-on-text-input-in-stand-alone-google-app-using-htmlserv