在使用“IFRAME”的沙箱模式时,无法使用Google Apps脚本获取链接。 [英] Unable to get links working in Google Apps Script when using sandbox mode of "IFRAME"
本文介绍了在使用“IFRAME”的沙箱模式时,无法使用Google Apps脚本获取链接。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Google Apps脚本中,下面的代码适用于默认沙箱模式,但是当我将沙箱模式更改为IFRAME时,代码不起作用。在IE11中,点击第一个按钮后我会看到一个空白页。在Chrome中,第一个按钮可以工作,但点击后续按钮会出现一个空白页面。
In Google Apps Script, the code below works for me in the default sandbox mode, but when I change the sandbox mode to IFRAME, the code does not work. In IE11, I get a blank page after clicking on the first button. In Chrome, the first button works but clicking the subsequent button brings up a blank page.
下面的代码取自这篇文章
/**
* Get the URL for the Google Apps Script running as a WebApp.
*/
function getScriptUrl() {
var url = ScriptApp.getService().getUrl();
return url;
}
/**
* Get "home page", or a requested page.
* Expects a 'page' parameter in querystring.
*
* @param {event} e Event passed to doGet, with querystring
* @returns {String/html} Html to be served
*/
function doGet(e) {
Logger.log( Utilities.jsonStringify(e) );
if (!e.parameter.page) {
// When no specific page requested, return "home page"
return HtmlService.createTemplateFromFile('my1').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
// else, use page parameter to pick an html file from the script
return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
my1.html
my1.html
<html>
<body>
<h1>Source = my1.html</h1>
<?var url = getScriptUrl();?><a href='<?=url?>?page=my2'> <input type='button' name='button' value='my2.html'></a>
</body>
</html>
my2.html
my2.html
<html>
<body>
<h1>Source = my2.html</h1>
<?var url = getScriptUrl();?><a href='<?=url?>?page=my1'> <input type='button' name='button' value='my1.html'></a>
</body>
</html>
推荐答案
Apps脚本现在仅支持IFRAME模式。 NATIVE支持消失了。请参阅此处
Apps Script now only supports IFRAME mode. NATIVE support is gone. See here
这篇关于在使用“IFRAME”的沙箱模式时,无法使用Google Apps脚本获取链接。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文