What about having jQuery use window.open on the 'ext' class? Since 'target=_blank' is not valid XHTML Strict.

Comments

quicksketch’s picture

No it's not valid XHTML strict, but because this attribute is added after page load your pages will still pass validators. Though you're right, since we have a convenient class, we could easily switch to using it instead.

quicksketch’s picture

As mentioned in #386988: External Links: add open in new window to statusbar, a good argument not to use JavaScript is the nice status bar message provided by Safari:

Open "http://example.com" in a new window.

Which we only get if using target="_blank" since Safari won't actually interpret a JavaScript popup script that would do the same thing. Of course Safari is the only browser that currently does this, so it's not that strong an argument.

webel’s picture

I also want XHTML strict compliance.

Would it be possible to introduce an optional settings field where one can introduce one's favourite Javascript "open in new window" hack (rather than hacking it into the external links module, as I'm about to do) ?

webel’s picture

Or should I say hack external.js.

    if (Drupal.settings.extlink.extTarget) {
      // Apply the target attribute to all links.
      $(external_links).attr('target', Drupal.settings.extlink.extTarget);
    }

If the work is done by JavaScript anyway, which not simply have one of the usual JavaScript tricks ?

webel’s picture

My hack fails:

  if (Drupal.settings.extlink.extTarget) {
//ORIG  $(external_links).attr('target', Drupal.settings.extlink.extTarget);

//override to force XHTML compliance FAILS
  $(external_links).attr('onclick', 'window.open(this.href); return false;');
    }

It seems that anything written to javascript attributes (like 'onclick') is filtered out.

Does anybody know why, or how I can ensure that 'target' is not used, rather the javascript instead ?

webel’s picture

This seemed to work for me (with all caveats, I'm not a jQuery expert):

$(external_links).bind("onclick", function() { window.open(this.href); return false;});
kentr’s picture

If the work is done by JavaScript anyway, which not simply have one of the usual JavaScript tricks ?

Popup blockers?

ambrojio’s picture

If you can't get the JS to work, assign the "rel" attribute to the link instead of "target", and then use one of the many JS "open in new window" scripts out there, that act on the rel attribute.

This, of course, once again raises the specter of the issue of W3C having deprecated the target attribute. It kind of makes sense to make that a user driven decision, but it's about 4 years ahead of both the general competency of web users at large--to be savvy enough to open external links in a new tab or window--and the expectations of 90% of web site buyers. It's a real pain in my hide, let me tell you.

ambrojio’s picture

As a follow up to that, it is possible to obtain XHTML compliant markup without altering the extlinks module at all. Disable the extlinks "open external links in a new window" in the module's admin. You will still have a class="ext" for external links. Then, use whatever method you want to include some Javascript on your page; I have a main.js file that I have a few functions stored in that I am including with drupal_add_js() in my template.php file. In that, I am calling an externalLinks() function in the jQuery equivalent of page.onload:

$(document).ready(function() {
	externalLinks();

        //other stuff here
});

And the function (adapted from http://perishablepress.com/press/2007/11/20/open-external-links-as-blank...) is:

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && ( anchor.getAttribute("class") == "ext" ))
		anchor.target = "_blank";
	}
}
quicksketch’s picture

Anyone thinking that "target" should be removed for compliance reasons... well it's compliant again in HTML 5. Figures. http://www.w3.org/TR/html5-diff/#new-attributes

kentr’s picture

Hmm, but what about XHTML. I haven't deciphered that document yet - is it saying that HTML5 replaces XHTML?

quicksketch’s picture

HTML 5 doesn't replace XHTML currently, but oddly it's what everyone is behind these days (read, Apple, Microsoft, Google, etc.) HTML5 will ultimately replace XHTML in 5 years as much as HTML 4 has been replaced by XHTML, which is never completely of course. It's just rather interesting. Even in XHTML, "target" was merely deprecated (meaning it was planning on being removed eventually), but now it seems that it's going to stick around after all as we move away from XHTML anyway.

AlexisWilke’s picture

Just my personal point of view, since the links are tweaked with JavaScript anyway, it certainly does not matter whether we have the target="_blank". And also, adding a bind function works too since we already know that JavaScript is available.

But I like the fact that HTML 5 includes the target attribute again. 8-)

My browser also already supports some CSS 3 so I can create shadows and outline, really cool! Can't wait to use that all over my themes.

webel’s picture

> I like the fact that HTML 5 includes the target attribute again
Agree.

iori57’s picture

Is 6.x-1.10 still using 'target' or switched to javascript now? Because I can't see 'target' anywhere when I'm viewing the source code now.. but it does open in new window.

Just to clear things up :) Thanks!

quicksketch’s picture

The "target" attribute is still used in the latest versions, but it's added by JavaScript, it's not there when the page loads initially.

iori57’s picture

Thanks for clearing things up!! I'm totally clueless when it comes to Javascript =.=

nancydru’s picture

Since the class is available, why not something like http://jaspan.com/external-links-in-new-window-without-target?

My big concern is that some of my users already use target="_blank" and I want it removed.

AlexisWilke’s picture

Nancy,

target is valid HTML. Deprecated does not mean dead & buried. Plus, in HTML 5 it's back and HTML 5 is right around the corner. Why bother removing something to put it back in tomorrow?!

http://dev.w3.org/html5/spec/links.html#attr-hyperlink-target

Alexis

nancydru’s picture

A) it will be duplicated by this module if it is already there.
B) it impacts the teaser length, in many cases reducing it by an entire paragraph.

Frankly, I agree that it should be back - at least until such a time that it can be specified in CSS.

quicksketch’s picture

This module doesn't affect the output HTML at all. If you turn off JavaScript you'll see that this module doesn't do anything to the HTML. All changes are done by JavaScript and it does not double-up the target attribute if it already exists.

quicksketch’s picture

Status: Active » Closed (won't fix)

Won't fix'ing per #14. "target" has always worked in every browser, it's back in HTML5, it's never going away, and the mechanism that External Links uses to add the target attribute has no effect on passing validators because the attribute is added by JavaScript. The bottom line is it doesn't cause any problems and it works exactly how people expect right now; there's no need to make any changes.

AlexisWilke’s picture

Nancy,

With my latest patch to the teaser, point #20 (B) is moot and I like that. 8-)

Thank you.
Alexis

See #221257: text_summary() should output valid HTML and Unicode text