如何使用Google Apps脚本中的javascript通过模态对话框模板更新侧边栏模板中的html? [英] How to update html in sidebar template from modal dialog template with javascript in Google Apps Script?
问题描述
我在模态对话框中有一个表单。提交对话框关闭并在后台执行一些操作的表单后。关闭模式对话框后,我也想更新侧边栏中的html(不刷新侧边栏)。我有一个带有加载器ID的div,并且隐藏类(这会阻止它可见)。在模态对话框关闭我想删除加载器div隐藏的类。如何从模态对话框模板访问该loaderdiv ?
I have a form in a modal dialog. After submiting a form that dialog closes and does some actions in the background. After closing the modal dialog I also want to update html in the sidebar (without refreshing the sidebar). I have a div with "loader" id in the sidebar with class hidden (which prevents it to be visible). On modal dialog close I want to remove class hidden from the "loader" div. How do I access that "loader" div from the modal dialog template?
推荐答案
您可以使用浏览器sessionStorage,设置一个计时器,并持续轮询可用信息。
You could use the browser sessionStorage, set a timer, and continuously "poll" for available information.
感谢评论,提出了一种不需要轮询的变体: p>
jquery
Thanks to a comment, a variation was suggested which eliminates the need for polling:
$(window).bind('storage',
function(e){if(e.key === "newValuesWereEntered"){doSomething()}});
脚本标记:
Script tag:
<script>
//Use a timer to keep checking for a completed action from another dialog
var theTimer;
window.setTheTimer = function() {
//To Do - Hide the Spinner
if (typeof(Storage) === "undefined") {
alert('HTML5 Storage is not supported. This App will not work in this browser. Please update your browser.');
return;
}
try {
window.sessionStorage.setItem("newValuesWereEntered","n"); //Make sure check value is reset
} catch(e) {
alert(e.error + ' You may have this apps cookies blocked in this browser, and/or this browser tab. Check cookie blocking.');
return;
};
theTimer = window.setInterval(monitorForTheResponse, 500); //Every 1/2 second, check for response value
};
window.monitorForTheResponse = function() {
var was_a_newValueEntered,dlgInfo;
was_a_newValueEntered = window.sessionStorage.getItem("newValuesWereEntered");
if (was_a_newValueEntered === 'y') {//Dialog just wrote value to window.sessionStorage
window.sessionStorage.setItem("newValuesWereEntered","n");//Reset
clearTimeout(theTimer);//turn off timer
//Get submitted values
dlgInfo = window.sessionStorage.getItem("newValuesToTransfer");
//To Do - Run code to display new value
};
};
</script>
具有传递给边栏的值的对话框必须将该值保存到会话存储
The dialog that has the value to pass to the sidebar must save that value to session storage
window.theValueWasSavedOrEntered = function() {
var arry,objectOfNewValues,strJSON;
try{
if (typeof(Storage) !== "undefined") {//Browser has local storage
window.sessionStorage.setItem("newValuesWereEntered","y"); //Set to yes
objectOfNewValues = {};
objectOfNewValues.valueOne = arry[0];
objectOfNewValues.valueTwo = arry[1];
strJSON = JSON.stringify(objectOfNewValues);
window.sessionStorage.setItem("newValuesWereEntered","y"); //Set to yes
window.sessionStorage.setItem("newValuesToTransfer", strJSON);
};
google.script.host.close();
} catch(e) {
SendErr({'message':'ERROR: ' + e.stack + ' message: ' + e.message});
};
};
这篇关于如何使用Google Apps脚本中的javascript通过模态对话框模板更新侧边栏模板中的html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!