XHTML Strict Anchor jQuery Fix


/ Published in: jQuery
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.