Reputation: 1090
I want to generate a url including some parameters based on input of the user. I do have an anchor and by using addMouseDownHandler or addClickHandler I can change the link of the anchor . Problem is this changed link will be activated ONLY after I click on the anchor a second time and the (at creation time) specified url will be activated the first time I click the anchor.
function onMouseDownAnchor(e)
{
Logger.log(JSON.stringify(e));// you can see the source parameter in e that returns the widgets ID of the button you clicked to call the handler
var app = UiApp.getActiveApplication();
var btnAnchor = app.getElementById('btnAnchor');
var newLink = 'http://www.google.com';
btnAnchor.setHref(newLink)
Logger.log('onMouseDownAnchor');
return app;
}
How can I change href of an anchor BEFORE the anchor activates the url it has at the time I click on it?
Upvotes: 1
Views: 192
Reputation: 1090
I found the solution myself . Instead of using
onMouseDownAnchor
I only need to use
onMouseOverAnchor
so the working code becomes
function onMouseOverAnchor(e)
{
Logger.log(JSON.stringify(e));// you can see the source parameter in e that returns the widgets ID of the button you clicked to call the handler
var app = UiApp.getActiveApplication();
var btnAnchor = app.getElementById('btnAnchor');
var newLink = 'http://www.google.com';
btnAnchor.setHref(newLink)
Logger.log('onMouseOverAnchor');
return app;
}
and, of course,
var anchor = myApp.createAnchor("", siteUrl)
.setId('btnAnchor').setName('bntAnchor')
.setHeight(heightButton).setWidth(widthButton)
.setStyleAttribute('backgroundImage', 'url(' + picButton + ')');
var onMouseOverAnchor = myApp.createServerHandler('onMouseOverAnchor');
anchor.addMouseOverHandler(onMouseOverAnchor); // This will change the href of the anchor
must have been created in the doGet-function
Upvotes: 1