The links package outputs links with the "target" attribute in the tag. An option in administration panel is available to choose whether the link will open in the current window or in a new window.

However, this "target" attribute has been deprecated in XHTML 1.0.
So any drupal web page containing a link and using XHTML does not validate because of the use of this attribute.
I suggest that the option is completely removed (today with tabbed browsers, users can choose if they open a new tab or not).
Another way would be to add an option in the admin panel to disable the use of this attribute.

CommentFileSizeAuthor
#4 target_patch.txt1.19 KBRayZ
#1 external.gif71 bytesfigaro

Comments

figaro’s picture

StatusFileSize
new71 bytes

The attribute target="_blank" is indeed invalid XHTML 1.0.

Ideally the user has already set its browser to force behaviour regarding internal and external links.
One could insert PHP code to append target="_blank" after every href-attribute and have links open up in a separate window if this forces behaviour not already superseded by the user, but this is not a recommended practice.

A more subtle and increasingly standard way of going about it is by appending an icon indicating an external link. Wikipedia is a notable example, see "External links and further reading" at the bottom of most of its pages.

For those with Gecko based browsers there is an advanced selector which could be used; add the following to your base.css:

a[href^="http:"] {
  background: url('../../images/external.gif') 100% 50% no-repeat;
  padding-right: 16px;
}

and place an icon indicating external links in your images folder no wider than 16pixels. Internet Explorer users will not see this icon. A sample icon is attached; copyright holder unknown.

figaro

syscrusher’s picture

I gave this issue a lot of thought, and have (for the moment at least) settled on a compromise. The ability to force "_blank" target is still present in the module, but I have added a clear warning that it is a controversial issue and that it causes invalid XHTML. This still leaves the choice with the system administrator, but advises them that there are consequences.

I like your idea of the special CSS, and may add that as a feature in the near future. Right now there is no special CSS for the Links package, so I first need to add the necessary support code to embed a reference to the CSS file in the overall Drupal output.

Scott

gothmog@drupal.org’s picture

Your compromise sounds good, as anyone can make its own choice. However I still have request:
With the latest version of the Links package posted yesterday (august 1st), under administer/settings/links, I have selected the option to 'Never' open links in new window.
When I use the weblink filter (with [weblink:45] for example), the XHTML produced still contains target="". I think in this case the target attribute should not be present at all instead of being there with no value. Only then a page would validate againt XHTML.
Thanks for your support and keep up the good work with this great module!

RayZ’s picture

Status: Active » Needs review
StatusFileSize
new1.19 KB


Try this patch.

gothmog’s picture

This patch works fine, thanks a lot !

Will this be integrated in the next version of the module?

lbjerryh’s picture

What does the patch do? My links still open in the same window under IE. Can someone clarify what this is suppose to accomplish. I use user submitted news on my site and I want the links to these stories to open in new windows to keep the user from leaving my site. How else can I accomplish this??

RayZ’s picture

Attempt to fix the HTML.

RayZ’s picture

Status: Needs review » Fixed

Moved my patch to http://drupal.org/node/117108. I the original issue here has been addressed, so I'm marking it fixed.

Anonymous’s picture

Status: Fixed » Closed (fixed)
nullbarriere’s picture

Yes, target _blank is back in HTML5, but... "User agents are encouraged to default to being configured to always reuse the current browsing context, or to at least provide that option to the user."

Anyway, how many themes will validate to HTML5 by, say, 2012?

At the moment target _blank does not validate to either XHTML 1.0 nor XHTML 1.1.

My solution:

1. I use rel="extern" instead of target="_blank".

BU Editor makes this easy by using

js:
var form = [
 {name: 'href', title: 'Link URL', required: true, suffix: E.imce.button('attr_href'), attributes: {size: 75}},
 {name: 'html', title: 'Link text', attributes: {size: 75}},
 {name: 'title', title: 'Link title', attributes: {size: 75}},
 {name: 'class', title: 'CSS Klasse', attributes: {size: 25}},
 {name: 'style', title: 'CSS Inline Style', attributes: {size: 75}},
 {name: 'rel', title: 'target', type: 'select', options: {'': '', extern: '_blank'}}
];
E.tagDialog('a', form, {title: 'Insert/edit link'});

as 'Insert/edit link' dialog.

2. I added an eventhandler to my BODY which adds target _blank to all Links with rel="extern" attribute:

2.1 In template.php add link to javascript: drupal_add_js(drupal_get_path('theme','my_theme').'/js/link_ext.js');

2.2 Put code in link_ext.js

function makeEventHandler(o,e,fn)
  {
  if(o.addEventListener)
    o.addEventListener(e, fn, true);
  else if(o.attachEvent)
    o.attachEvent('on'+e, fn);
  }


//initialisieren
function initAnchors()
  {
  
  if(!document.getElementsByTagName)return;   //dann eben nicht

  aArr = document.getElementsByTagName('a');

  for(i=0;i<aArr.length;i++)
    if(aArr[i].getAttribute('href')&& aArr[i].getAttribute('rel') == 'extern')aArr[i].target = '_blank';
  }

//initialisieren für window.onload anmelden
makeEventHandler(window,'load',initAnchors);

The HTML validates, and works in the major browsers with javascript enabled, otherwise no harm is done (links just don't open in new window).