I read an article that suggested working around a method that is not strictly valid (target="_blank") by applying the rules after pageload via javascript.
That strikes me as a large case of using the letter of the law to defeat the spirit of the law, but I don’t want to criticize before knowing if it’s really a problem. Is there something about code validation that makes it only matter before any scripts have executed?
Try to make your page as valid as possible. You don’t make it valid for W3, but for your users. Invalid HTML needs to be corrected by the browser to be displayed. Every browser may do this differently, so invalid markup may (theoretically) result in your page looking different in each browser.
If you add the markup from JavaScript, it will be just as invalid and it gives you the same risk. The only thing you did, is trick the W3 validator, because it won’t execute the Javascript. So in fact, it tests another page than your users will see. If you do that, your validation is useless.
That said, I believe
target="_blank"works in most any browser, so if you really need it, and can’t change the doc type, well, you’ll just have to live with that one error you get from the validator.And then again, the markup itself looks ok (no omitted elements, everything is nicely escaped and quotes), so it’s just a single attribute that may be ignored by the browser. Worst case, the browser will ignore the target. Theoretically a browser could fail to render the page, but in this case that is very unlikely.