我遇到了点击按钮的问题,我需要通过Google应用制作商转到超链接。你们最好推荐一种方法来实现这个目标
答案 0 :(得分:0)
尝试使用Link小部件:
https://developers.google.com/appmaker/scripting/api/widgets#Link
如果您希望在新标签页中打开链接,也可以将目标设置为_blank。
答案 1 :(得分:0)
您可以使用
window.open('www.your_link.com','_blank');
按钮onClick事件
答案 2 :(得分:0)
对于不熟悉App Maker的未来读者,快速回答是:
// ex: with the Link widget
var link_widget = app.pages.PageName.descendants.LinkWidget;
// use some function that gets your href
var valid_link = getMyHref();
// set the href
link_widget.href = valid_link;
答案 3 :(得分:0)
我找到了解决方案。 关键是要使用Google App Maker中的HTML小部件。然后您解析该字符串,可以将其转换为html并将其加载到字段中。为此,您必须考虑以下因素:
//Converts string to html with clickable links
function linkify(text){
//splits by </br> and a space
words = replaceAll('</br>',' ',text).split(' ');
link_types = ['https://','http://','www.','.com','.co.uk'];
links = [];
//Scan all the words looking for a URL
words.forEach(function(word){
//console.log(word);
var link_found = false;
//Check if it contains any of the URL identifiers
link_types.forEach(function(link_type){
if(links.indexOf(word)===-1){
if(!link_found){
if(word.indexOf(link_type)!== -1){
link_found = true;
//appends to list of existing links to avoid creating multiple hyperlinks of the same URL
links.push(word);
href ='';
//if the link doesn't contain http then it formats the URL to include it
if(word.indexOf('http')===-1){
href+='http://';
}
href+=word;
//Replaces all occurences of the link to a html format
text = replaceAll(word,'<a href="'+href+'" target="_blank">'+word+'</a>',text);
}
}
}
});
});
return text;
}
linkify('随机文本https://google.com的负载更多随机文本...。')
输出:“加载了更多随机文本的随机文本 https://google.com ...”
编辑:
如下定义replaceAll函数
function replaceAll (search, replacement,text) {
var target = text;
return target.replace(new RegExp(search, 'g'), replacement);
};