0

I am trying to get the current URL in Google HTML services , But I do not get the correct one , I use the following methods.

function pprueba(url){
console.log("Prueba : "+url);
console.log("Pruena 2 :"+window.location.href);
console.log("Pruena 3 :"+google.script.run.getScriptUrl());
console.log("Pruena 4 :"+window.location);
console.log("Pruena 5 :"+$(this).attr('href'));
}

in the server side I have this function , the first prueba are getting as parameter the result of getScriptUrl.

function getScriptUrl() {  
    var url = ScriptApp.getService().getUrl();
    return url;
}

Prueba : https://script.google.com/macros/s/AKfycbwaCJjgSiUs6LiQq0yocXNU93DVtD30lLTEWi1NEcs/dev

Pruena 2 :https://n-4xmbqpfn3z7t4od5wj623x3uicdbwgqeelan7da-0lu-script.googleusercontent.com/userCodeAppPanel

Pruena 3 :undefined

Pruena 4 :https://n-4xmbqpfn3z7t4od5wj623x3uicdbwgqeelan7da-0lucript.googleusercontent.com/userCodeAppPanel

Pruena 5 :undefined

but what I expect is

https://script.google.com/a/CompanyName.com/macros/s/AKfycbwaCJjgSiUs6LiQq0yocXNU93DVtD30lLTEWi1NEcs/dev

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Research how google.script.run is used. You need to use successHandlers – TheMaster Mar 11 '20 at 14:40
  • Does this answer your question? [how to use google.script.run as if it was a function](https://stackoverflow.com/questions/11487045/how-to-use-google-script-run-as-if-it-was-a-function) – TheMaster Mar 11 '20 at 14:47
  • Related: https://stackoverflow.com/questions/14220321 – TheMaster Mar 11 '20 at 14:48
  • @TheMaster ,Yes , I know it , i have this funcion(google.script.run.withSuccessHandler(prueba).getScript Url();) on onload that is what PPrueba get as parameter . the other lines was to the purpuse of show what I tryed before post – Hector Alcaraz Mar 11 '20 at 16:24
  • I'm sorry Do you want to get the top url without using server sidecode? – TheMaster Mar 11 '20 at 17:07
  • Where are you calling ```getScriptUrl()```? – Mateo Randwolf Mar 12 '20 at 10:06
  • Hi @MateoRandwolf here window.onload = function() { google.script.run.withSuccessHandler(pprueba).getScriptUrl(); }; – Hector Alcaraz Mar 12 '20 at 12:10
  • Try the following instead to make sure this is not the issue: ```pprueba(getScriptUrl)```. Pprueba function needs a parameter to be passed, in your case it needs the return of the function that gets the url. – Mateo Randwolf Mar 19 '20 at 13:26

0 Answers0