/    Sign up×
Community /Pin to ProfileBookmark

unobtrusive onclick event…

I have a small problem with my unobtrusive onclick event in javascript…

it opens a new window if you click on a link in the html. However, after opening the new window/tab it also follows the link in the old window (which it shouldn’t..) I’am using prototype. This occurs only in IE7 en FF3 , in IE6 Opera everything is fine and behaves like it should.

below is my snippet, any help/suggestion is higly appreciated!

[code]
function external_link(link) {

var el = Event.element(link);

window.open(el.href);
Event.stop(event);
/* this is where it should stop following the link in the old window */

return false;
}
function init() {
var links = $A(document.getElementsByTagName(‘a’));
links.each(function(link) {
if (link.getAttribute(‘rel’) == ‘external’) {

Event.observe(link,’click’,function(e){ external_link(e); },false);
}
});
}
Event.observe(window,’load’,init);
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 03.2008 — My suggestion is to stop using "prototype", "JQuery" or any other framework/library for simple things like that. Learn and use plain javascript.
Copy linkTweet thisAlerts:
@Jeff_MottJul 14.2008 — Wow. I just found this thread... almost two weeks old and still not answered. Pipo, here's the problem: [font=courier]Event.stop(event)[/font] should be [font=courier]Event.stop(link)[/font], since [font=courier]link[/font] is the name you gave to the variable.
×

Success!

Help @pipo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...