Lehan Coetzee
Lehan Coetzee

Reputation: 424

Google Apps Script, anchor creating a redirect when clicked

I'm creating a script that logs a user into a site. Everything works but for some reason when the user clicks on the link to go to their profile the link opens in a new window and at first redirects before going to the correct page.

For example:

The correct link is: https://sites.google.com/site/examplelehan/Jan_Moolman but the moment the link is clicked the link that is actually executed in the address bar changes to: http://www.google.com/url?q=https%3A%2F%2Fsites.google.com%2Fsite%2Fexamplelehan%2FJan_Moolman&sa=D&usd=2&usg=AFQjCNFXLLswDh2AWCBpYi54jNXxpZVGPQ

So it seems as if www.google.co.za is being pre-pended to the url. I've seen other posts as well but none of them seem to be offering working solutions. A few posts have said that this occurs when the link is created without the http:// prefix but I've tested that and the same problem occurs.

I've also tried using .createHTML in order to create the link but for some reason the link doesn't show, any other HTML I use seems to work so I guess that's why Google created the Anchor function.

Thank you in advance for your help.

Upvotes: 0

Views: 1628

Answers (1)

Serge insas
Serge insas

Reputation: 46812

In this issue tracker comment Eric Koleda suggested a workaround using UrlShortener Services . I tested it with your link (http://goo.gl/HRPfU) and it seems to be a working solution.

EDIT : to answer your comment, here is a working example :

function test(){
var shorturl=short('https://sites.google.com/site/examplelehan/Jan_Moolman');
Logger.log(shorturl);
}
//
function short(longurl){
  var toShorten = UrlShortener.newUrl().setLongUrl(longurl);
  var short = UrlShortener.Url.insert(toShorten).getId();
  return short
  }

note that this API has to be activated before it can be used (see docs)

Upvotes: 2

Related Questions