views:

2759

answers:

5

IE8 will sometimes prevent links from spawning if they have target=_blank set.

This problem appears to be limited to corrupt installs of IE, such as when installing several versions side-by-side.

I edited this question once I found the answer, and hopefully this will save someone else some time. The answer is in the comments of the first answer listed.

A: 

This is because target="_blank" is not valid under XHTML Strict Mode. See:

http://www.8164.org/xhtml-strict/

The following should work in all cases.

<script>window.open("http://www.80vul.com/test/ie8-1.htm");&lt;/script&gt;

I presume that as of IE8 Beta 1, the default mode is now STRICT instead of TRANSITIONAL.

the.jxc
This doesn't work for me, though in my document I'm forcing IE7 mode as follows: <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
Andrew Johnson
I get a "class not registered" error in IE.
Andrew Johnson
"Class not registered" when opening new windows means your IE8 install is corrupt.
EricLaw -MSFT-
http://www.debugtheweb.com/test/strict.htm works properly when IE8 is installed correctly.
EricLaw -MSFT-
Eric, you hit the nail on the head. I have "side-by-side" IEs (6,7,8, etc.) installed on a VirtualBox instance. When I check the page through a real windows box, it works. Thanks!
Andrew Johnson
Yes, sadly that's one of the reasons that we don't recommend the "side-by-side" hacks. VPC is the only supported way to get side-by-side today. Thanks for the update!
EricLaw -MSFT-
A: 

What about if you use target='blank' ? I know it's not THE same, but you will get the popup/window open in a new instance, and your site could validate for XHTML Strict Mode :)

Andrea
This doesn't work for me.
Andrew Johnson
sorry, I misplaced a quote. It should been target='blank'
Andrea
Still doesn't work :(
Andrew Johnson
for the record, it's not the '_blank' that's not allowed in XHTML 1.0 or 1.1 strict, it's the target attribute on anchor or link elements. It was (intentionally) left out of the DTD. If using target='blank' validated for you as XHTML 1.0 or 1.1 Strict then it was an error on the validator's part. That said, most browsers still accept it and process it, valid or no.
Gabriel Hurley
A: 

Yeah, XHTML Strict Mode doesn't accept target="_blank".

If you don't want to keep using window.open everywhere, you can use rel="external" and some extra Javascript like the following, using JQuery:

$(document).ready(function() {
    $("a[rel='external']").attr("target","_blank");
});

EDIT: To set all generated links:

 $("a[rel='external']").ready(function() { 
    $("a[rel='external']").attr("target","_blank");
 });

Or, without jQuery, you can use the script, found here:

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("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 
window.onload = externalLinks;
João Marcus
This doesn't work. First of all, the links are created with javascript, and as such don't exist onload. I tried setting a.rel and a.target, but this doesn't work.
Andrew Johnson
Well, this is supposed to be a collaboration site, not a "give me a solution that works out of the box" site.
João Marcus
Hence my continued collaboration.
Andrew Johnson
Your collaboration consists of "this doesn't work". You shouldn't downmod people because the solution "doesn't work". It works, just not exactly the way you want it to.
João Marcus
A: 

I know this is already answered, but I just wanted to tell about the jQuery's live binding functionality:

$("a.myclass").live("click",function() {
    $(this).attr("target","_blank");
});

This example sets the 'target="_blank"' attribute to any link with the class "myclass", even those created with Javascript.

João Marcus
+2  A: 

This depends upon which stand-alone IE8 that you use. I found this to be a problem while using "Final Builds Site - Internet Explorer Collection" (http://finalbuilds.edskes.net/iecollection.htm) version 1.6.0.3. The developer has now fixed this bug as of Ver. 1.6.0.4, and links with target="_blank" now work as expected.

Paul Solomon