Manual     Reference     Scripting   
  
Unity Manual > Advanced > Web Player Deployment > HTML code to load Unity content   

HTML code to load Unity content

Web Player content is loaded in the browser using the Unity Web Player's plugin or ActiveX control. The HTML code required to load and display web player content is different for Microsoft's Internet Explorer compared to all other browsers. This is because Internet Explorer uses ActiveX Controls and therefore an object tag must be used whereas all other supported browsers use plugins and therefore an embed tag must be used instead.

The HTML file generated by Unity when building a web player contains all the commonly required functionality - it does Unity plugin detection, enables easy web player installation, and supports all browsers that can run Unity Web Player. In most cases you don't have to modify the HTML file at all. This document describes the inner workings of HTML code required for Unity content.

The minimal HTML required to load Unity Web Player content in all supported browsers is:

<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394"
    width="600" height="450"
    codebase="http://webplayer.unity3d.com/download_webplayer/UnityWebPlayer.cab#version=2,0,0,0">
    <param name="src" value="MyDataFile.unity3d" />
    <embed id="UnityEmbed" src="MyDataFile.unity3d" width="600" height="450"
        type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" />
</object>

In the above example the object and embed tags are used in such a way that Internet Explorer uses the object tag and ignores the embed tag, while all other browsers use the embed tag and ignore the object tag.

In both the object and embed tags there are various parameters that control how the web player content is displayed:

  • src: Defines the path to the web player data file to be displayed.
  • height, width: Defines the display size for the web player content. The values provided can be pixel values as expressed in the example above (600 pixels wide and 450 pixels tall) or as percentage values (width="100%" for example).
  • id: Can be used by external browser scripts in order to communicate with the web player content. The default id values included when publishing web player content are UnityObject for the object tag and UnityEmbed for the embed tag, but those can be changed to different values as necessary.

The other parameters found in the object and embed tags above are required and should not be modified. The codebase and pluginspage parameters point to the location from which the Unity Web Player can be installed. The classid parameter is a unique identifier for the Unity Web Player ActiveX Control and the type parameter is the content mime-type for the Unity Web Player plugin.