2014-10-29 70 views
0

我正在編寫一個電子表格的Google腳本,在將其部署爲Web應用程序後,您將獲得一個URL(https://script.google.com/macros/s/.../dev)。參數化URL中的腳本

我想在URL(例如,(https://script.google.com/macros/s/.../dev/param)傳遞一個輸入參數。

我怎樣才能在腳本中獲取此參數的值?

+0

要獲取JS當前的URL,你可以使用'document.URL'谷歌是否允許你添加額外的參數,仍然直接到你的腳本? – Quince 2014-10-29 14:39:12

+0

DocumentApp.getActiveDocument()。getUrl()將返回URL,但由於某種原因,這不起作用,所以我不能嘗試使用額外的參數。 – nightcod3r 2014-10-29 14:50:01

+0

爲了讓我的觀點更清晰:我正在使用可部署腳本,我正在嘗試做的是在doGet()函數的範圍內。 – nightcod3r 2014-10-29 14:51:21

回答

1

你可以在末尾添加一個字符串在部署Web應用程序的網址,只需插入一個問號和獨立的論點&

例如:

the .dev  https://script.google.com/macros/s/AKfycb___vWxs/dev?val=test&otherVal=otherTest 

the .exec https://script.google.com/macros/s/AKfycb___vWxs/exec?val=test&otherVal=otherTest 

演示代碼:

function doGet(e) { 
    var valToReturn = ContentService.createTextOutput('the parameters were '+e.parameter.val+'\nand\n'+e.parameter.otherVal).setMimeType(ContentService.MimeType.TEXT); 
    return valToReturn; 
} 

你會在你的瀏覽器中得到兩個參數值