Generate HTML based on browser
I am using object to play audio file in my html page. I need to use tow objects, one for IE and one for other browsers The current code is shown below
<object id='audioPlayer' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject'
height="42" width="250">
// giving parameters here
<%-- !IE--%>
<object type="video/x-ms-wmv" data="<%: Model.recordSourcePath %>" width="251" id="audioPlayerMozilla"
height="42">
// giving parameters here
</object>
</object>
Its works fine.But the problem is i need to give diiferent id's for both objects(ie,audioplayer and audioPlayerMozilla). If i give same id for both java script is not works in mozilla. I must want to get access to this object using same id . Can i generate htmls based on browser
a sample i wanted is shown below
if (IE)
开发者_如何学Python {
<object id='audioPlayer' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject'
height="42" width="250">
// giving parameters he
</object>
}
else if(!IE)
{
<object type="video/x-ms-wmv" data="<%: Model.recordSourcePath %>" width="251" id="audioPlayer"
height="42">
// giving parameters here
</object>
}
Here, note that the id i used is same. So i can handle them genereally. Is there any way to do anything like this?
What you're looking for is known as "IE Conditional Comments". Rather than explain the entire thing, I'll link to an article which does that for me.
- http://www.quirksmode.org/css/condcom.html (better)
- http://www.positioniseverything.net/articles/cc-plus.html
Example:
<!--[if IE]
<p>This is IE!</p>
![endif]-->
<!--[if !IE]>-->
<p>This isn't IE!</p>
<!--<![endif]-->
Specific Example:
<!--[if IE]
<object id='audioPlayer' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' type='application/x-oleobject' height="42" width="250"></object>
![endif]-->
<!--[if !IE]>-->
<object type="video/x-ms-wmv" data="<%: Model.recordSourcePath %>" width="251" id="audioPlayer" height="42"></object>
<!--<![endif]-->
This method is only good for distinguishing between different versions of IE, and as a generality, browsers that are not IE. For example, you can have one version for IE6, another for IE7, IE8 and IE9, and another for all other browsers. You couldn't though, using this method, have one specific output for firefox.
You could just avoid the hack (conditional code) altogether and use a player such as this: http://www.jplayer.org/
It's going to give you a more feature rich player with guaranteed compatibility.
精彩评论