问题描述
我在模态对话框中有一个表单.提交表单后,对话框关闭并在后台执行一些操作.关闭模态对话框后,我还想更新侧边栏中的 html(不刷新侧边栏).我在侧边栏中有一个带有loader"id 的 div,其中隐藏了类(这可以防止它可见).在模式对话框关闭时,我想从加载器"div 中删除隐藏的类.我如何从模态对话框模板访问那个加载器"div?
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.
感谢评论,提出了一种无需轮询的变体:
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>
//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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!