I'm having an issue where tapping on a button, I need it to open a hyperlink. How can I achieve this?
Asked
Active
Viewed 1,397 times
4 Answers
0
Try to use Link widget:
https://developers.google.com/appmaker/scripting/api/widgets#Link
You can also set target to _blank if you want your link to open in new tab.

Pavel Shkleinik
- 6,298
- 2
- 24
- 36
0
You can use
window.open('www.your_link.com','_blank');
in button onClick event

Andrey Koltsov
- 1,956
- 6
- 24
- 43
-
Thanks! I have figured this out. – Tiktak132 Jun 21 '17 at 13:11
0
For future readers who are new to App Maker, the quick answer is:
// 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;
0
I've found a solution to this. The key is to use the HTML widget in Google App Maker. Then you parse the string can convert it to html and load it into the field. To do this you must consider the following:
- New Lines must be converted to
- Create a function to replaceAll - (replaces all instances found in a string)
- What count as a link, to do this use the list link_types
//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('Loads of random text https://google.com more random text....')
output: 'Loads of random text https://google.com more random text....'
EDIT:
Define the replaceAll Function as below
function replaceAll (search, replacement,text) {
var target = text;
return target.replace(new RegExp(search, 'g'), replacement);
};

Samuel Lopez
- 87
- 1
- 9
-
Hi, this looks just like what I am looking for, I don't know what you mean by creating a replaceAll function though. Can you please explain so I can fix this? I have been working on this one for weeks :/ – Kat Nov 17 '18 at 12:23
-
Thanks. So the result I'm getting, as I am adding this to a comment field, is that it returns like this: http://www.google.com in the comment box. I really need it to be the hyperlink.The reason I'mm putting it into the comment box is because as the object is created, it only needs this like if it is a specific type of object being created.. – Kat Nov 18 '18 at 00:08