Google apps script 在锚定将激活url之前更改href
我想根据用户的输入生成一个包含一些参数的url。 我有一个锚,通过使用addMouseDownHandler或addClickHandler,我可以更改锚的链接。 问题是,只有在我第二次单击锚点后,此更改的链接才会被激活,并且(在创建时)指定的url将在我第一次单击锚点时被激活Google apps script 在锚定将激活url之前更改href,google-apps-script,anchor,href,Google Apps Script,Anchor,Href,我想根据用户的输入生成一个包含一些参数的url。 我有一个锚,通过使用addMouseDownHandler或addClickHandler,我可以更改锚的链接。 问题是,只有在我第二次单击锚点后,此更改的链接才会被激活,并且(在创建时)指定的url将在我第一次单击锚点时被激活 function onMouseDownAnchor(e) { Logger.log(JSON.stringify(e));// you can see the source parameter in e that r
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;
}
在锚激活我点击时的url之前,我如何更改锚的href?我自己找到了解决方案。 而不是使用
onMouseDownAnchor
我只需要使用
onMouseOverAnchor
因此,工作代码变为
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;
}
当然
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
必须已在doGet函数中创建