Page 1 of 1

jQuery - External links (problems)

Posted: Sun Mar 25, 2007 3:00 pm
by Skara
Hmph. Well, I never did like javascript, but jQuery is pretty cool.

Anyway, I'm marked up as XHTML 1.1. So, no target attribute. I have a link I want to open in a new window. For some reason, my jQuery isn't working quite right. It does open in a new window, but it opens a local page /undefined.

Code: Select all

 $(document).ready(function(){
   $("a[@rel='external']").click(function() {
      window.open(this.href);
      return false;
   });
});

Code: Select all

<a href='http://blahblahexternal.com/' rel='external'>text</a>
Instead of opening blahblahblahexternal.com, it opens mysite.com/currentfolder/undefined.

Posted: Sun Mar 25, 2007 3:32 pm
by nickvd
Find out what 'this' is...

console.log(this) (assuming you are running firefox with firebug)

or

console.dir(this) (to see a tree-view of the internals of the object)

Posted: Sun Mar 25, 2007 3:47 pm
by Skara
er... haven't heard of firebug. But I re-enabled the code and it worked. But... now the shadow part of my code doesn't work. O.o
I must be doing something funky like leaving something out...

The first line doesn't work (it DID work), the rest (currently) work:

Code: Select all

 $(document).ready(function(){
   $("#gallimgs img").wrap("<div class='shadow0'><div class='shadow1'><div class='shadow2'><div class='shadow3'></div></div></div></div>");
   $("div.news").wrap("<div class='shadowb0'><div class='shadowb1'><div class='shadowb2'><div class='shadowb3'></div></div></div></div>");
   $("div.news").css('border','1px solid #777');
   $("td.newstd").css('padding','0');
   $("a[@rel='external']").click(function() {
      window.open(this.href);
      return false;
   });
 });

Posted: Sun Mar 25, 2007 5:30 pm
by nickvd
Okay, by "Doesn't Work" what exactly do you mean? :?:

Posted: Sun Mar 25, 2007 10:04 pm
by Skara
it doesn't do anything.
nothing.
I get no error messages.

Posted: Mon Mar 26, 2007 2:58 am
by Kieran Huggins

Code: Select all

$(function(){
   $("a[@rel='external']").click(function() {
      window.open($(this).attr('href'));
      return false;
   });
});