2016-08-12 68 views
0

我試圖關閉我開了一個無模式對話框對話框如下:google.script.host.close關閉不工作

var html = HtmlService.createHtmlOutputFromFile('dialog') 
.setSandboxMode(HtmlService.SandboxMode.IFRAME) 
.setWidth(150) 
.setHeight(150); 
DocumentApp.getUi().showModelessDialog(html, 'Help'); 

對話框HTML看起來像這樣

<!DOCTYPE html> 
    <html> 
    <head> 
    <base target="_top"> 
    </head> 
    <body> 
    Working on it... 
    </body> 
</html> 

現在我想關閉對話框,但我無法使它工作。這是我的。

var html = HtmlService.createHtmlOutputFromFile('close'); 

的緊密HTML如下:

<!DOCTYPE html> 
<html> 
    <head> 
    <base target="_top"> 
    <script> 
     google.script.host.close(); 
    </script> 
    </head> 
    <body> 
    </body> 
</html> 

我試圖與 '()',並沒有google.script.host.close。任何想法我做錯了什麼?

謝謝你的時間!

+1

那麼,是否顯示「close.html」文件?您可以嘗試將代碼更改爲'window.onload = function(){google.script.host.close();}'我猜你希望close.html在打開時立即關閉? –

回答

0

據我所見,這是一個相當容易解決的問題。你不想創建一個新的HTML文件來關閉舊的文件,你想關閉第一個。你應該做的是這個。

首先,像你一直在打開你的對話框。

其次,把你的host.close()函數中的你help.html內:

function closeHelp() { 
    google.script.host.close(); 
}; 

然後,就找了個地方將其關閉。我通常只是在任何對話框的底部製作一個按鈕。

<button onclick="closeHelp()"> Close </button> 

這將關閉您的窗口。