Does HTML understand "if-else"?
Let's say I have Flash-version of and non-Flash version of my website. When a user comes to my website, is there any way to create the following logic:
if (user has flash-plugin installed) { load flash website }
else { load non-flash website }
W开发者_如何学Pythonhile we are here. Can I do the same for the bandwidth control? Let's say a Cable customer visits my websites. He has no problem loading my 10mb fully loaded flash website with background videos. But if someone with a slow internet connection visits my website, can I skip the Flash website and re-direct that user to non-Flash website?
If there's no way to accomplish this, is there any workaround, any at all?
Thanks in advance!
HTML has a limited set of "if/else" test on the browser's capabilities, e.g. whether it can handle scripts (<noscript>
), frames (<noframes>
), etc.
Your case on Flash-plugins can be handled by fallback content of <object>
, for example:
<object type="application/x-shockwave-flash" data="x.swf" width="400" height="300">
<param name="movie" value="x.swf" />
<p>Your browser does not support Flash etc etc etc.</p>
</object>
(See Providing alternative images if Adobe Flash isn’t available for more alternatives.)
But it's not possible to have a bandwidth control with HTML alone.
You must use javascript. Here is a plugin detection tool on JS.
http://www.oreillynet.com/pub/a/javascript/2001/07/20/plugin_detection.html
var isFlashInstalled = detectFlash();
if (isFlashInstalled)
{
window.location = "main_with_flash.htm";
}
else
{
window.location = "main_no_flash.htm";
}
No, this is not doable in pure HTML. You would need the assistance of JavaScript, or maybe a server-side language like PHP, or Server Side Includes (although detecting Flash is best done using JS.)
The only "if/else" there is is for the presence of JavaScript. Anything inside a noscript
tag will be shown only in browsers that don't support JavaScript or have it turned off.
<noscript>You have JavaScript turned off!</noscript>
You would use Javascript. Here is Adobe's Flash detection instructions page: http://www.adobe.com/support/flash/how/shock/javaplugs/
Connection speed is a little more complicated and requires doing a bunch of things to test capabilities (again with javascript). Here is a proof-of-concept of this method: http://alexle.net/archives/257
HTML is a document format, not a language. There are a few limited things you can do based on how the browser interprets certain tags, but you should really be using Javascript.
You can't do this in HTML. But you can use Javascript for it. (Something like this)
If you are using Python with Django or Flask, you can use Jinja. You can pass in arguments in the Python portion and use them in the HTML. The syntax for Jinja is:
{% if condition %}
<!--HTML here-->
{% elif condition %}
<!--HTML here-->
{% else %}
<!--HTML here-->
{% endif %}
As you can see, when you are done with your if
statement, you need to use the {% endif %}
statement. Jinja also allows for many other things like for loops and template inheritance. Hope this helps anyone using Python with Django or Flask!
if-else definitely works in html files, but i don't think you can use it for what you are suggesting. Also it is actually javascript so it may not be what you are looking for.
example of an if else statement:
<script>
if (A == 1) {
B = 7
} else {
B = 9
}
</script>
精彩评论