views:

1113

answers:

3

I was having this discussion with one of my colleagues. He created a piece of code that put an a-href around an object where a flash is to be loaded. When I saw this I almost cried out and told him to use the clickTag instead.

He told me that it works fine with the a-href. I checked it out, and the code worked fine in ie6-8 and firefox (all having flashplayer 9 or 10 installed).

Since I KNEW that its a really bad idea to use a-href I did a little research about why not to use it.

From there I checked out the standards (http://www.w3.org/TR/html401/struct/objects.html) and googled around.

But I did not find any explanation why it should or should not work (I know sometimes it does not work).

We ended up with a solution to use both - the surrounding a-href and passed the clickTag (fyi: we do not know what kind of swf will be displayed since it comes from a cms).

Why does the a-href/flash sometimes work and sometimes it does not and what would be the "standard" way to do something like that? What about other included objects (svg/movie/audio/..?) Is there a standard that defines how such things (as clicks on embedded objects like flash or a media player) are handled (ie. the javascript way to stop propagating the click event)?

+2  A: 

I would recommend against it. My computer is running 64-bit Linux, and Flash behaves a little funny in Firefox. (For one thing, it acts as though the z-index is always greater than everything else.) I haven't tested it, but I suspect it wouldn't behave well. Bottom line is that this is the sort of thing you'd want to test on all browsers on all platforms, and it'd just be better to avoid it if possible.

Adam Crume
Exactly... deviating away from how people do things normally is just asking for a cross-browser cross-platform issue. ESPECIALLY when it comes to embedded objects.
Zoidberg
Thats not really the question - I know from experience that its a bad idea - the question is more: Is there a standard that defines how such things (as clicks on embedded objects) are handled?
Niko
@Niko: Well, the title of the question is: "Is a a-href around an object (ie. flash) a bad idea?"
Adam Crume
@adam - true updated the title and the adapted the text a little
Niko
+4  A: 

There is no standard against it, but it will definitely lead to unpredictable results across different browser/platform combinations. Doing a simple search and going through the results shows that there are many people who have had issues with just hyperlinking the swf.

Adding both the hyperlink and the clickTag is rather pointless, you're duplicating the functionality since if the visitor has the correct version of Flash then they're going to get the Flash movie and the clickTag is going to be used. What you should do is have the hyperlink as a fallback, so that if Flash isn't installed then people can still access your hyperlink. Libraries such as SWFObject make this very easy to do.

Jason Berry
what - like in this case - you do not know in advance what kind of swf is being uploaded/displayed by the content management? This is why I was telling the whole story. afaik there is no guarantee that the href will work. Also what about other objects except flash?
Niko
Hyperlinking objects is always going to behave unpredictably because the object itself can intercept the click event and execute it's default click handler. It may or it may not work, depends on the object and depends on the browser/platform combination!
Jason Berry
Thats what I figure. Either the obejct propagates the event - thus executing the a, or not. I am still looking for a statement from ie. w3c or at least mozilla, adobe or ms that describe this behavior. From your answer and my own research I gather that there simply is no standard or clear definition that explains/defines how it should work... I was hoping someone could point to a clear explanation.
Niko
A: 

The standard way to do it is to use the [onclick] attribute to pass in a JS expression, or to listen for the click mouse event, once a click has been captured on the inline <embed> and <object> before focus is transferred over to the plug-in.

I'm thinking if the <object> and <embed> wrap around the plug-in content properly, then <a> should wrap properly around <object> and <embed> as well. I'd also like to naturally believe that when <object> and <embed> capture the click mouse event, that it also properly bubbles up. But I'm not 100% sure if this kind of behavior can be altered by the plug-in, causing <a> not getting it's display properly computed or some other event model not firing the event on <a>.

kRON