jQuery - External links (problems)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

jQuery - External links (problems)

Post 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.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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)
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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;
   });
 });
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Okay, by "Doesn't Work" what exactly do you mean? :?:
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

it doesn't do anything.
nothing.
I get no error messages.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Code: Select all

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