Hey there, this site is pretty old now. I've decided to leave it up as I put a lot of work into it and would hate to see it disappear.

Display Tags For 'validation'

How To Use target="_blank" Correctly In XHTML & HTML Strict

Neal Grosskopf
1/28/2008 7:56:01 PM

Occasionally web developers like their links to pop-up in a new window. Often times this is because they are linking to a non-web file type or are linking to an external web site.

The easiest way to accomplish this is to place the target="_blank" attribute on an anchor. Unfortunately if you validate your code with the W3C you will find that it is not valid to use that practice. Do not fear, there is a solution!

The workaround err, solution, is to place an onclick on the anchor tag. The code below will open a new window, get the value in the href attribute and cancel the action the href attribute would take.

<a href="http://www.nealgrosskopf.com" onclick="window.open(this.href);return false;">Link</a>
Replies:7
Views:6941

CSS Diagnostics - Find Deprecated Elements Using CSS

Neal Grosskopf
2/18/2008 9:51:35 PM

This article is no longer my most current version of CSS Diagnostics. Please see my latest article A Second Look At CSS Diagnostics for the latest version.

I've been getting so many hits on this article that I decided to update it. I have added a few more elements and attributes and changed the colors around. The most severe code is colored red while less severe is colored yellow. There is also a medium severarity that is colored orange. Also remember that elements have solid borders while attributes have dotted boreders. Also check out my Test Suite showing examples of CSS Diagnostics in action.

The other day I was reading Eric Meyer's blog and stumbled across his version of what he likes to call CSS diagnostics. So what is CSS diagnostics? It's a method to highlight those ugly spots in your code, you know <font color="red" size="+1">. Yeah under the hood, somewhere on your website garbage like that exists, yet it's always so hard to hunt down and fix. Never fear CSS diagnostics is here!

CSS Diagnostics allows users to find deprecated elements using CSS and also find find deprecated attributes using CSS. Sorry to have to repeat myself so much here, I'm trying to rank high in SEO with some of these terms since this is still very much uncharted territory.

So how do you use CSS Diagnostics? It's easy! It requires a pretty good knowledge of CSS 2 & CSS 3 selectors and a good knowledge of deprecated HTML elements and attributes.

Follow these steps:

  1. Highlight Deprecated Elements

    applet, basefont, center, dir, font, isindex, menu, s, strike, u, marquee, blink, acronym /* html 5, use abbr */ { border: 5px solid red !important; }
  2. Highlight Deprecated Attributes

    br[clear], hr[noshade], *[color], *[bordercolorlight], *[bordercolordark], *[bordercolor], *[background], *[bgcolor], *[nowrap], body[alink], body[link], body[text], body[vlink], body[bottommargin], body[leftmargin], body[rightmargin], body[topmargin], body[marginheight], body[marginwidth], ol[compact], ul[compact], *[start], img[hspace], img[vspace] *[align], *[valign], *[height], *[width], ul[type], ol[type], li[type], basefont[size], font[size], hr[size] { border: 5px dotted red !important; }
  3. Highlight Proposed Deprecated Elements

    input[type="button"], input[type="reset"], input[type="submit"], tt, embed, big, small { border: 5px solid orange !important; }
  4. Highlight Proposed Deprecated Attributes

    a[target], table[cellpadding], table[cellspacing], map[name], img[name], object[name], form[name], iframe[name], a[name], table[border], img[border], object[border], input[border], object[classid], object[codebase], embed[quality], embed[pluginspage] { border: 5px dotted orange !important; }
  5. Highlight Specific Empty Elements:

    div:empty, span:empty, li:empty, p:empty, td:empty, th:empty { padding: 20px; border: 5px solid yellow !important; }
  6. Highlight Specific Empty Attributes

    *[alt=""], *[title=""], *[class=""], *[id=""], a[href=""], a[href="#"] { border: 5px dotted yellow !important; }

Putting it all together:

Place this code at the end of your stylesheet:

/* Deprecated Elements */ applet, basefont, center, dir, font, isindex, menu, s, strike, u, marquee, blink, acronym /* html 5, use abbr */ { border: 5px solid red !important; } /* Deprecated Attributes */ br[clear], hr[noshade], *[color], *[bordercolorlight], *[bordercolordark], *[bordercolor], *[background], *[bgcolor], *[nowrap], body[alink], body[link], body[text], body[vlink], body[bottommargin], body[leftmargin], body[rightmargin], body[topmargin], body[marginheight], body[marginwidth], ol[compact], ul[compact], *[start], img[hspace], img[vspace] *[align], *[valign], *[height], *[width], ul[type], ol[type], li[type], basefont[size], font[size], hr[size] { border: 5px dotted red !important; } /* Proposed Deprecated Elements */ input[type="button"], input[type="reset"], input[type="submit"], tt, embed, big, small { border: 5px solid orange !important; } /* Proposed Deprecated Attributes */ a[target], table[cellpadding], table[cellspacing], map[name], img[name], object[name], form[name], iframe[name], a[name], table[border], img[border], object[border], input[border], object[classid], object[codebase], embed[quality], embed[pluginspage] { border: 5px dotted orange !important; } /* Empty Elements */ div:empty, span:empty, li:empty, p:empty, td:empty, th:empty { padding: 20px; border: 5px solid yellow !important; } /* Empty Attributes */ *[alt=""], *[title=""], *[class=""], *[id=""], a[href=""], a[href="#"] { border: 5px dotted yellow !important; }

Download The Full Stylesheet

Notes:

It's a good idea to create consistency with your rules. I chose to highlight all attributes in a solid border while highlighting all elements in a dotted border. Also choose different colors for different meanings.

It should also be pointed out that you should use the most standards complient web browser when checking for results. Currently I found that Firefox 2 seems to work best as it comes with many other addons that can work side by side with the custom CSS.

I enjoyed reading Eric's ideas on it but felt I could expand it a bit more. Certainly other's can expand on my version as well. Feel free to contact me if you see something I'm missing.

Sources

Replies:12
Views:33239

Embedding Flash Without Click To Activate Using Valid HTML

Neal Grosskopf
4/7/2008 6:24:00 PM

I am currently working on a website for a client and one of their requests was that their home page have some animation featuring some of their promotions. Now I know the first thing you are saying is "please, God, say it aint so, not FLASH!" Yes I know flash is evil, I absolutely hate it but in this instance it is the best tool for the job.

I won't tell you how annoying the software is to make a flash movie but I will tell you how annoying it is to simply embed a flash file in your web page using valid HTML.

Here is the jist of what I needed to accomplish:

  1. Valid HTML
  2. A movie that doesn't repeat
  3. A movie with a clickable link/region
  4. A movie with a transparent background
  5. Avoid annoying "Click to activate this control" in Internet Explorer

I was able to do these things but never a combination of all of them. I first tried using a javascript library called SWF Object since that is something I've seen on our work websites. SWF Object worked fine although it failed miserably with the transparent background. I tried pretty much everything I could think of to get that to work even using examples from the documentation but to no avail it sucks.

On a side note, people are seriously over-using these javscript libraries. Within a few years every legitimate web developer will have forgotten getElementById() and will assume that javascript can naturally select individual elements by class name with no problem. I think libraries are the cheap way out, not to mention how many KB they take up. Check out one of my work websites. It has over 12 javascript files, clocking in at over 240KB. Gez.

After that I tried simply hardcoding the html into the webpage. This worked fine in IE but Firefox and the likes required the noncompliant EMBED tag to make it work. Even worse was I was now faced with the annoying Click to activate this control problem in Internet Explorer.

After various modifications to my code I ended up just taking the invalid EMBED tag wrapped with an OBJECT tag and through it in an external javascript file using multiple document.writes

Everything worked now, except the code technically wasn't valid HTML even though the W3C validator said so. Then today I read this article on Alistapart and specifically this comment. After that it all made sense to me. After hours of toiling I had found the solution and everybody was wrong!

This code not only validates but it works. The only drawback here is we still have the annoying click to activate this control problem in Internet Explorer. The trick here was to remove the ClassID attribute since that stopped it from working in Firefox and adding the DATA attribute.

<object type="application/x-shockwave-flash" data="/yourfile.swf"> <param name="movie" value="/yourfile.swf"> <param name="loop" value="false"> <param name="wmode" value="transparent"> </object>

Embeding Flash Without Click To Active And Using Valid HTML

Simply place this script in an external .JS file and call it using the bottom function. Viola, no more click to activate, transparent background, doesn't repeat, and work fine in all browsers without the stupid EMBED tag and without annoying conditional comments for IE.

<script type="text/javascript"> function writeFlash(file) { document.write('<object type="application/x-shockwave-flash" data="'+file+'">') document.write('<param name="movie" value="'+file+'">') document.write('<param name="loop" value="false">') document.write('<param name="wmode" value="transparent">') document.write('</object>') } </script> <script type="text/javascript"> writeFlash("/yourfile.swf"); </script>

G00gle B0mb Attempts

Replies:2
Views:9583

A Second Look At CSS Diagnostics

Neal Grosskopf
6/18/2008 8:44:34 PM

Earlier this year I wrote an article inspired by Eric Meyer's on CSS Diagnostics: Selecting Deprecated Elements With CSS. The article was a smash, and I my site traffic has gone up like crazy ever since. I was unaware that this niche in the standards community would be so popular. Unfortunately I did not put as much thought into my initial diagnostics other than just trying to improve on Eric's code. Enter part 2.

My IE Has Bugs!

After applying my original diagnostics code to several projects (at work, and on my recent site re-design) I realized that Internet Explorer wasn't quite getting it right. In fact sometimes, IE was selecting incorrect elements. What came from this was I needed to be more careful in the selectors I used and that using the "*" selector resulted in some weird things in IE. What also came from that was a bug in IE that selects the IMG tag when the selector calls for the proprietary IMAGE element.

I decided to go out to the HTML 4.01 specification and find exactly what attributes and elements are deprecated and which aren't. That way I could create a more authentic version of the diagnostics tool rather than just adding my personal opinion on what ought to be deprecated and what shouldn't. This resulted in CSS Diagnostics 2.0.

Diagnostics Gone Famous

For my second rendition of the project, I decided that I should create a Google Code Project and host my diagnostics there. I'm not completely sure if that is a good or bad thing to do. My goals are to keep traffic coming to my own site and not Google's but perhaps the two can live together. I also learned that you can embed the Google Analytics tracking code directly into the Google Code web page thus allowing me to track traffic to that area. This makes me care less about traffic going there because if I can use GA, then I can fell like I actually own those pages.

On to the code:

  1. Highlight Empty Attributes

    I chose some common attributes that people may forget to fill in. Feel free to remove the href="#". I like to use this one because while developing a website, I forget to change # links to their proper pages and this helps me catch them in the copy.

    img[alt=""], area[alt=""], *[class=""], a[href=""], a[href="#"], *[id=""], *[title=""] { border: 5px dotted yellow !important; }
  2. Highlight Proposed Deprecated Attributes

    These are a list of attributes that aren't formally deprecated but I personally believe should be. Generally this is because there is a better alternative such as CSS or using IDs on elements rather than NAME.

    body[background], table[background], td[background], th[background], input[border], table[border], table[cellpadding], table[cellspacing], object[codebase], img[height], object[height], table[height], a[name], form[name], img[name], object[name], a[target], area[target], td[valign], th[valign], img[width], object[width], table[width] { border: 5px dotted orange !important; }
  3. Highlight Deprecated Attributes

    These attributes are officially deprecated by the W3C per the HTML 4.01 specification. If you are using the TRANSITIONAL DTD CSS Diagnostics is a great way to move your code to STRICT. It should also be noted that these should appear AFTER empty, and proposed deprecated elements due to specificity in CSS.

    applet[align], caption[align], div[align], h1[align], h2[align], h3[align], h4[align], h5[align], h6[align], hr[align], iframe[align], img[align], input[align], legend[align], object[align], p[align], table[align], body[alink], applet[alt], applet[archive], body[background], body[bgcolor], td[bgcolor], tr[bgcolor], table[bgcolor], img[border], object[border], br[clear], applet[code], applet[codebase], basefont[color], font[color], dir[compact], dl[compact], menu[compact], ol[compact], ul[compact], basefont[face], font[face], applet[height], td[height], th[height], applet[hspace], img[hspace], object[hspace], script[language], body[link], applet[name], hr[noshade], td[nowrap], th[nowrap], applet[object], isindex[prompt], hr[size], font[size], basefont[size], ol[start], body[text], li[type], ol[type], ul[type], html[version], body[vlink], li[value], applet[vspace], img[vspace], object[vspace], hr[width], td[width], th[width], applet[width], pre[width] { border: 5px dotted red !important; }
  4. Highlight Non-W3C Proprietary HTML Attributes

    These are a list of proprietary HTML attributes. Using these in your code is more offensive than using a deprecated attribute, since these were never warrented by the W3C. Use of these attributes should be avoided at all costs.

    body[bgproperties], *[bordercolor], *[bordercolordark], *[bordercolorlight], body[topmargin], body[rightmargin], body[bottommargin], body[leftmargin], table[frame] { border: 5px dotted magenta !important; }
  5. Highlight Empty Elements

    These selectors will highlight empty elements within your markup. I've commented out a few selectors that I found didn't jive with my personal website but feel free to de-comment these and use them on your website.

    /*span:empty,*/ /*div:empty,*/ li:empty, /*p:empty,*/ td:empty, th:empty { border: 5px solid yellow !important; }
  6. Highlight Proposed Deprecated Elements

    Here is a list of elements I feel should be deprecated. INPUT Types should be deprecated because the BUTTON element is a much better choice and allows for easier selection of all website BUTTONs especially in IE6.

    input[type="button"], input[type="reset"], input[type="submit"], tt, big, small { border: 5px solid orange !important; }
  7. Highlight Deprecated Elements

    These elements are formally deprecated in the HTML 4.01 STRICT specification.

    applet, basefont, center, dir, font, isindex, menu, s, strike, u, listing, plaintext, xmp { border: 5px solid red !important; }
  8. Highlight Non-W3C Proprietary HTML Elements

    All of these elements are proprietary, meaning they are not part of the W3C spec and never have been. They include some of the more infamous elements such as the MARQUEE and the BLINK tags. I've commented out the IMAGE selector because IE7 and under will select the IMG tag as well, so use at your own risk.

    audioscope, bgsound, blink, bq, comment, embed, fn, ilayer, /*image,*/ keygen, layer, limittext, marquee, multicol, nobr, noembed, nolayer, nosmartquotes, rt, ruby, server, sidebar, spacer, wbr, xml, blackface, shadow { border: 5px solid magenta !important }
  9. Highlight XHTML 1.0 Strict Deprecated Attributes

    Since many people use XHTML I read the XHTML spec and threw in a few deprecated attributes specific to XHTML.

    a[name], applet[name], form[name], frame[name], iframe[name], img[name], map[name] { border: 5px dotted lime !important }
  10. Highlight XHTML 1.0 Strict Prohibitions

    There are also prohibitions in XHTML, essentially elements that cannot appear nested inside other elements.

    a > a, pre > img, pre > object, pre > big, pre > small, pre > sub, pre > sup, button > input, button > select, button > textarea, button > label, button > button, button > form, button > fieldset, button > iframe, button > isindex, label > label, form > form { border: 5px solid lime !important }
  11. Highlight Deprecated Classes From Old Version Of Website

    I found this area of CSS Diagnostics especially helpful during my last site re-design. When I re-designed my site, I threw out all my old CSS and started from scratch. What resulted was a lot of left over classes in my markup that was non existent in my external stylesheet. This is a great way to call out those "old" classes that aren't being used anymore.

    .toolbg, .ulnone, span.b, ul.list, .eleven, .lines, .wide, .select, table.form, form td.b, table .top, .gallerypic, .iegallery, .pic, .image, .transparent, .wht, .blk, .blue, .dkgray, .ltgray, .brown, .quote, .greyhover { border: 5px groove red !important; }
  12. Highlight Deprecated JavaScript Functions From Old Version Of Website

    The same can be applied to old JavaScript functions. I found numerous references to old function calls so I devised a way to highlight deprecated JavaScript functions.

    input[onfocus*="normal1px()"], input[onfocus*="change1px()"] { border: 5px dashed red !important; }
  13. Highlight Known 404 Page Links

    Another problem I ran across during my redesign was deleted web pages. I devised a way of highlight known 404 pages using CSS. You can substitute the URLs I have below with you own known 404 pages. A great way to determine 404 pages is to look at your server log files or to use Google Webmaster Tools.

    a[href*="/designs/web/web1/"], a[href*="/designs/web/web2/"], a[href*="/designs/web/web3/"], a[href*="/designs/aitp/aitp-fvtc/"], a[href*="/designs/aitp/aitp/"], a[href*="/forms/contact.asp"], a[href*="/forms/email.asp"] { border: 5px double red !important; }

Putting It All Together:

/* Empty Attributes */ img[alt=""], area[alt=""], *[class=""], a[href=""], a[href="#"], *[id=""], *[title=""] { border: 5px dotted yellow !important; } /* Proposed Deprecation Due To CSS */ body[background], table[background], td[background], th[background], input[border], table[border], table[cellpadding], table[cellspacing], object[codebase], img[height], object[height], table[height], a[name], form[name], img[name], object[name], a[target], area[target], td[valign], th[valign], img[width], object[width], table[width] { border: 5px dotted orange !important; } /* W3C HTML 4 Strict Deprecated Attributes - http://www.w3.org/TR/html401/index/attributes.html */ applet[align], caption[align], div[align], h1[align], h2[align], h3[align], h4[align], h5[align], h6[align], hr[align], iframe[align], img[align], input[align], legend[align], object[align], p[align], table[align], body[alink], applet[alt], applet[archive], body[background], body[bgcolor], td[bgcolor], tr[bgcolor], table[bgcolor], img[border], object[border], br[clear], applet[code], applet[codebase], basefont[color], font[color], dir[compact], dl[compact], menu[compact], ol[compact], ul[compact], basefont[face], font[face], applet[height], td[height], th[height], applet[hspace], img[hspace], object[hspace], script[language], body[link], applet[name], hr[noshade], td[nowrap], th[nowrap], applet[object], isindex[prompt], hr[size], font[size], basefont[size], ol[start], body[text], li[type], ol[type], ul[type], html[version], body[vlink], li[value], applet[vspace], img[vspace], object[vspace], hr[width], td[width], th[width], applet[width], pre[width] { border: 5px dotted red !important; } /* Non W3C Proprietary HTML Attributes - http://en.wikipedia.org/wiki/Non-standard_HTML_tags#Proprietary_HTML_attributes */ body[bgproperties], *[bordercolor], *[bordercolordark], *[bordercolorlight], body[topmargin], body[rightmargin], body[bottommargin], body[leftmargin], table[frame] { border: 5px dotted magenta !important; } /* Empty Elements */ /*span:empty,*/ /*div:empty,*/ li:empty, /*p:empty,*/ td:empty, th:empty { border: 5px solid yellow !important; } /* Proposed Deprecated Elements */ input[type="button"], input[type="reset"], input[type="submit"], tt, big, small { border: 5px solid orange !important; } /* W3C HTML 4 Strict Deprecated Elements - http://www.w3.org/TR/html401/index/elements.html */ applet, basefont, center, dir, font, isindex, menu, s, strike, u, listing, plaintext, xmp { border: 5px solid red !important; } /* Non W3C Proprietary HTML Elements - http://en.wikipedia.org/wiki/Non-standard_HTML_tags */ audioscope, bgsound, blink, bq, comment, embed, fn, ilayer, /*image,*/ keygen, layer, limittext, marquee, multicol, nobr, noembed, nolayer, nosmartquotes, rt, ruby, server, sidebar, spacer, wbr, xml, blackface, shadow { border: 5px solid magenta !important } /* XHTML 1.0 Strict Deprecated Attributes - http://www.w3.org/TR/xhtml1/#h-4.10 - http://www.w3.org/TR/xhtml11/changes.html#a_changes */ a[name], applet[name], form[name], frame[name], iframe[name], img[name], map[name] { border: 5px dotted lime !important } /* XHTML 1.0 Strict Prohibitions http://www.w3.org/TR/xhtml1/#prohibitions */ a > a, pre > img, pre > object, pre > big, pre > small, pre > sub, pre > sup, button > input, button > select, button > textarea, button > label, button > button, button > form, button > fieldset, button > iframe, button > isindex, label > label, form > form { border: 5px solid lime !important } /* Deprecated Classes From Old Website */ .toolbg, .ulnone, span.b, ul.list, .eleven, .lines, .wide, .select, table.form, form td.b, table .top, .gallerypic, .iegallery, .pic, .image, .transparent, .wht, .blk, .blue, .dkgray, .ltgray, .brown, .quote, .greyhover { border: 5px groove red !important; } /* Dreprecated JavaScript From Old Website */ input[onfocus*="normal1px()"], input[onfocus*="change1px()"] { border: 5px dashed red !important; } /* 404 Pages */ a[href*="/designs/web/web1/"], a[href*="/designs/web/web2/"], a[href*="/designs/web/web3/"], a[href*="/designs/aitp/aitp-fvtc/"], a[href*="/designs/aitp/aitp/"], a[href*="/forms/contact.asp"], a[href*="/forms/email.asp"] { border: 5px double red !important; }

Summary:

It is best to use different colors and borders to apply meaning to what error you have made in your code. I like to use yellow for minor, orange for moderate, red for severe, and magenta for extremely severe.

I also like to apply different border styles depending on what the problem may be. Dotted for me means there is a bad attribute, solid means there is a bad element. Other border styles have their own meanings as well.

Considerations:

Make sure to place this at the end of your stylesheet and to leave in the !important rules so that they override any rules that may be inline.

It is also best to use a standards compliant browser when testing. IE7 is ok but I would personally suggest Firefox 3 because it supports standards better and because it has other add-ons that make web development easier and diagnostic testing easier.

Download:

I've set up a Google Code Project so feel free to download it.

Replies:9
Views:24015

Make YouTube Embed HTML Validate

Neal Grosskopf
6/24/2008 6:52:11 AM

It's nice to allow end users to post their own videos on my website, but the problem is, the HTML YouTube provides for users to embed video does not validate.

YouTube uses the EMBED tag wrapped by an object tag to embed their videos which is not a standards based way of embeding video. Embeding video is easy and there is no need to resort to YouTubes method.

Rather than put the burden on my end users to properly embed video, I decided to write a function that would convert any videos posted from YouTube and display them in a standards based way.

Converting YouTube's Garbage Embed Code To Valid HTML

  1. The function requires that you pass it the user's embed code and a link to the YouTube video

    Function YouTubeCleanup(embed,link)
  2. Next we check if the embed variable contains the phrase "youtube" in it

    if len(replace(embed,"youtube","")) <> len(embed) then
  3. Then I build the new path to the YouTube video using the link variable

    url = "http://www.youtube.com/v/" & replace(link,"http://www.youtube.com/watch?v=","") & "&hl=en"
  4. Next I build the output for the new standards based way of embeding flash video

    embed = "<object type=""application/x-shockwave-flash"" data=""" & url & "&hl=en""><param name=""movie"" value=""" & url & """></object>"
  5. Finally I return the value of the embed variable. Note that if the embed variable did not initially contain "youtube" in it, it will return the variable's default value and no harm has been done.

    YouTubeCleanup = embed

Putting It All Together

Function YouTubeCleanup(embed,link) if len(replace(embed,"youtube","")) <> len(embed) then url = "http://www.youtube.com/v/" & replace(link,"http://www.youtube.com/watch?v=","") & "&hl=en" embed = "<object type=""application/x-shockwave-flash"" data=""" & url & "&hl=en""><param name=""movie"" value=""" & url & """></object>" end if YouTubeCleanup = embed End Function
Replies:6
Views:13936

<< Back