2014-05-13 54 views
1

我想要生成一個包含一些基於用戶的輸入參數的網址。 我有一個錨點,並通過使用addMouseDownHandler或addClickHandler我可以更改錨點的鏈接。 問題是這個改變的鏈接將被激活,只有當我第二次點擊錨點,並且(在創建時)指定的url將在我第一次點擊錨點時被激活。更改href之前錨會激活url

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; 
} 

如何更改錨點的href在錨點激活其點擊它時的url?

回答

1

我自己找到了解決方案。 而不是使用

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功能