Null Pointer
Null Pointer

Reputation: 9299

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)
    {
   <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?

Upvotes: 0

Views: 483

Answers (2)

bpeterson76
bpeterson76

Reputation: 12870

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.

Upvotes: 0

Jeff Parker
Jeff Parker

Reputation: 7517

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.

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.

Upvotes: 1

Related Questions