Posted By

digitalclubb on 12/13/10


Tagged

xhtml strict jquery anchor


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

czehner


XHTML Strict Anchor jQuery Fix


 / Published in: jQuery
 

The most annoying thing I find working with the strict doctype is the inability to send users off to a site in a new window.

To combat this, I always use the above snippet.

Some people just stick the attribute on the anchors when the page loads, however for semi-accessibility, I think this works well.

  1. $('a.ext').each(function() {
  2. var $self = $(this), extTitle;
  3. if ($self.attr('title') !== undefined && $self.attr('title') !== "") {
  4. extTitle = $self.attr('title');
  5. $self.attr('title', extTitle + ' (opens in a new window)');
  6. } else {
  7. $self.attr('title', 'This link will open in a new window');
  8. }
  9. }).bind({
  10. 'click':function() { window.open($(this).attr('href')); return false; },
  11. 'keypress':function(e) { if (e.keyCode == 13){window.open($(this).attr('href')); return false;} }
  12. });

Report this snippet  

You need to login to post a comment.