2013-09-16 101 views
1

我在Google網站中增量構建HTML,我需要用超鏈接替換某些內容。儘管如此,根據文檔<a>標籤是不允許的。Google網站應用程序腳本用超鏈接創建HTML

所以...我如何在以下示例中將anchor轉換爲可以附加的HTML字符串?

for(var ii=1; ii < strings.length; ii++) { 
    html += "<h2>An item</h2>"; 
    html += "<div class='item'>"; 
    anchor = app.createAnchor("click for further info...", "http://x.com?id=y"); 
    html += strings[ii].replace(/<link>/g, anchor); 
    html += "</div>"; 
} 
app.add(app.createHTML(html)); 

我不認爲.add(anchor)會在這種情況下工作,因爲我需要更換一個佔位符字符串。

回答

3

Html類只能包含html文本,它不是Class Anchor實例的容器。不過,您可以將Anchors放入任何UiApp容器元素中。上的谷歌網站的Apps腳本小工具內

實施例:

Screenshot

這在FlowPanel錨的一個例子。雖然任何面板類型都可以,但流程面板使用包含元素的默認排列方式,這意味着我們可以使用inlineLabels散佈錨點元素,並最終將文本顯示爲單行。

代碼:

// Simulate html text + link by combining 
// inlineLabels & anchors in a flowPanel. 
function doGet() { 
    var app = UiApp.createApplication(); 

    var flow = app.createFlowPanel(); // To simulate text + link 
    flow.add(app.createInlineLabel('If you want to see kittens, ')); 
    flow.add(app.createAnchor('click here', 'https://www.google.com/search?q=cute+kitten+pictures&tbm=isch')); 
    flow.add(app.createInlineLabel('.')); 
    app.add(flow); 

    return app; 
} 
相關問題