views:

410

answers:

5

I'm developing an ASP.NET website that will need to support non-flash users.

In case the user's browser doesn't support Flash, or they have Flash disabled, I'd like to download a large splash image to the browser.

However I don't want to waste bandwidth downloading it if the Flash does render properly.

So is it possible to test, from the server-side using .NET code, whether the browser supports flash? I looked through the 'Request.Browser' object, but couldn't find anything relevant to Flash.

+1  A: 

You might try using some server var:

'HTTP_ACCEPT' against 'application/x-shockwave-flash'

Not sure about .NET but it works most of the time in php. This does not work in Safari but for what you're doing that should be fine. You'll be saving yourself some bandwidth 95% of the time. PHP example(not .NET but you get the idea):

if (strstr($_SERVER['HTTP_ACCEPT'], 'application/x-shockwave-flash')){
    $hasFlash = true;
}
Travis
+1  A: 

Given your requirement I'd better use a Flash detection script which will detect Flash capabilities on the client and will redirect the user to another page instead of downloading the SWF file. You can find many scripts on Kirupa or you can use the one that is generated in the Flash publish options dialog

victor hugo
+1  A: 

The client-side flash detection is probably the better way to go. However, do keep in mind that you may have users with JavaScript disabled, such as people using the NoScript plugin. You have three basic choices for dealing with this that I can see.

  1. Ignore it. Perhaps you feel not enough people will be in this situation to be worth worrying about.

  2. Check for it, and have an indicator come up asking the user to enable JS for a better experience on this site. This is usually done by having the notice render in the page, and having JS code to disable or hide the rendering of that element.

  3. Attempt to support reasonably good site operation without JavaScript. This would probably involve having the large image load by default, and stopping that load from happening before it starts. That could be tricky.

Curt Sampson
+1  A: 

You should not be dealing with this on the server side. Most Flash detection/embedding scripts do this sort of behaviour by default. I highly recommend SWFObject.

  • Create a <div> with your image (or any html you want really) inside it
  • Give it an ID eg: <div id="flash">
  • Tell SWFObject to override that div block with a Flash player

If they have disabled, they see the unchanged html. If they have javascript enabled but no Flash plugin, they see the html as well. Basically, they'll see the Flash only if they have javascript and the Flash plugin.

That's about as good as it gets.

Soviut
A: 

There certainly are some reasons that you want to detect flash on the server side. We need certain parts to be completely replaced or left out on a page if flash is not available. Its not as simple as displaying alternate content in the exact place where the flash was. We need to replace html structure further up. And we need to do that even if Javascript is not available. It is not really an option to let javascript rewrite the page IF Flash is available and we can't just redirect to another page.

Sven Deichmann