Problema ao chamar com Onload
Não consigo executar com o código abaixo, ai ele ta com um botão com onclick para a função makeshort, gostaria que ele chamasse sozinho, sem necessidade do botão... tentei load dentro da função, uma outra função no final do body chamando essa, e outras tantas, mas sempre da erro na linha: var request = gapi.client.urlshortener.url.insert({
obrigado.
> <html>
<head>
</head>
<% urlteste = "http://meusite.com.br" %>
<script type="text/javascript">
function makeShort(){
var longUrl="<%= urlteste %>"
var request = gapi.client.urlshortener.url.insert({
'resource': {
'longUrl': longUrl
}
});
request.execute(function(response)
{
if(response.id != null)
{
str = longUrl;
str2 = response.id;
document.getElementById("longo").value = str;
document.getElementById("curto").value = str2;
}
else
{
alert("error: creating short url \n"+ response.error);
}
});
}
function load(){
//Get your own Browser API Key from https://code.google.com/apis/console/
gapi.client.setApiKey('AIzaSyCY3yh-X-KyT05Cm5ffK3McxymOMdEwAMs');
gapi.client.load('urlshortener', 'v1',function(){document.getElementById("longo").value="";});
}
window.onload = load;
</script>
<script src="[https://apis.google.com/js/client.js](https://apis.google.com/js/client.js)"> </script>
<body>
<input type="button" value="Create Short" onclick="makeShort();" /> <br/> <br/>
<input type="text" id="longo" value="" /> <br/> <br/>
<input type="text" id="curto" value="" /> <br/> <br/>
</body>
</html>Discussão (2)
Carregando comentários...