SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Important - IE gotcha with target attribute!

    Hi all,

    Thought I'd post this, as it got me the other day. Something in a recent security update for IE6.x has caused problems with the target attribute (for anchors definitely, possibly for frames too). Here's an example of a target attribute we were using:

    Code:
    <a href="foo.asp" target="2006-w302893_test_stackbar_default">
    This worked fine for years, but broke about two weeks ago in IE (still works fine in Firefox). We discovered anything other than alphanumeric characters in the target attribute now causes a problem in IE - it will ignore any JS in an onClick attribute if there are special characters in the target.

    I checked the standards and frametarget in the DTD for HTML is of CDATA type, which I believe means it should take any string, right?

    Also, I know from the W3C guidelines that our target should start with an alphabetical character [(a-zA-Z)] and doesn't, but this doesn't appear to be IE's gripe, as if you change the target name to just "2006" it works fine.

    We only need a unique string, so we got around this by URL encoding our target string and removing all the % symbols, like so:

    Code:
    target="20062Dw3028935Ftest5Fstackbar5Fdefault"
    We then added an 'a' to the start of all targets, just to 100% certain they all start with an alphabetical character, as per the standards:

    Code:
    target="a20062Dw3028935Ftest5Fstackbar5Fdefault"
    And there you go - one legal, standards compliant and IE compatible unique target attribute.

    Note, if you have hyphens, underscores or anything else "strange" in your target attributes on your website, you're setting yourself up for a future IE headache. Be warned!

    Cheers,

    G

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Wow, thanks for the heads up Greg

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •