views:

27

answers:

1

This code loads the href into a new window and into self, why is this? Shouldn't return false; stop the default click?

//get links in paragraphs
var first_p = $$('#client_work p a');

//get first link
var client_link = first_p[0];

if(client_link) {
    $(client_link).observe('click', function() {

        var mylink = window.open(client_link.href, 'new_window', '_self');
        return false;   

    })
}
+3  A: 

Try this

//get links in paragraphs
var first_p = $$('#client_work p a');

//get first link
var client_link = first_p[0];

if(client_link) {
    $(client_link).observe('click', function(event) {

        var mylink = window.open(client_link.href, 'new_window', '_self');
        Event.stop(event);   

    })
}
vooD
And so that was all I needed.Thank you voDQuestion: return false does not work here because Im in an event handler?
Richard Testani
Prototype provides abstraction layer for event handling (therefore event propagation stopping). Read documentation http://www.prototypejs.org/api/event
vooD