Hi Brian,

Thanks for the quick response.

Yes, the data appended to the href is a time-sensative encrypted
querystring variable, so the data needs to be generated after the
click-event.

I was trying to avoid setting the location variable since the anchors
that this method will be affecting can be either target=_self or
target=_blank.

I tried this, but the target assignment isn't respected:

function callback(link,json)
{
        location.target=link.attr('target');
        location.href=json.href;
}

In any case it would be useful to delay the redirect of the anchor
until an asynchronous process is completed.

-John


On Feb 19, 10:06 am, brian <bally.z...@gmail.com> wrote:
> This seems like it would be a pretty slow user experience. Why don't
> you just append the data to the link before the user clicks on it.
> Unless the data are time-sensitive, that is. Otherwise, couldn't you
> just update all the links with the appropriate data well before any of
> them are actually used?
>
> Anyway, if you want to send a user somewhere, just do location.href = 
> your_href
>
> On Thu, Feb 19, 2009 at 8:22 AM, KihOshk <goo...@microsopht.com> wrote:
>
> > Hi,
>
> > I am using getJSON() to retrieve some data I want appended to a
> > clicked anchor's href before it navigates. I first tried binding the
> > update function to the anchor's click-event, but while the callback is
> > pending the browser navigates to the original href. I then tried both
> > unbind() and one() in combination with click(); basically, I override
> > the click-event completely with a preventDefault(), and then call the
> > element's click() in the callback.
>
> > The following example simulates the callback-delay, and updates the
> > href, but the final click() does not force navigation on the anchor as
> > I expected it should; I manually needed to click it again.
>
> > Does anyone have a solution? Thanks.
>
> > <script>
> > $(function(){
> >        $('a').one('click',function(event){
> >                                                        test($(this));
> >                                                        
> > event.preventDefault();
> >                                                        });
> > });
>
> > function test(link)
> > {
> >        setTimeout(function(){callback(link,{href:'http://jquery.com'})},
> > 1000);
> > }
>
> > function callback(link,json)
> > {
> >        link.attr('href',json.href);
> >        link.unbind('click');
> >        link.trigger('click');
> > }
> >                </script>
> >        </head>
> >        <body>
> >                <a href="http://msn.com";>test</a>
> >        </body>

Reply via email to