Summary: This page lists specific differences between IE Mobile AJAX support and desktop IE.

Adding On-Demand Script

AJAX pages sometimes need to programmatically add <script> tags that reference JavaScript from another location. One of the most common uses of this technique is when calling Web services that return data in JavaScript Object Notation (JSON) format.

In most browsers, desktop IE included, you add the on-demand script by creating a new <script> tag, setting the src attribute to the script's location, and then adding the new script tag to the browser's DOM. This technique does not work on IE Mobile for two reasons. First, prior to Windows Mobile 6, IE Mobile does not support dynamically creating new nodes in the browser DOM. Second, IE Mobile (Windows Mobile 6 included) does not allow you to programmatically set the src attribute on a <script> tag. Instead, IE Mobile requires that new script tags be added using the innerHTML property of another tag such as a <div> tag.

Windows Mobile 2003 and Newer

Prior to Windows Mobile 6, IE Mobile does not support dynamically creating new DOM nodes therefore you need to include a <div> tag in the HTML to act as a place holder for the script. You can then add the script tag by creating a string that includes the complete <script> tag including the src attribute and then assigning that string to the innerHTML property of the existing <div> tag.

		 <html>
		   <head></head>
		   <body>
		     ... 
		     ...
		     <div [id='sciptPlaceHolder></div>]
		   </body>
		 </html>
	

You can now add a new script tag as shown here

		 var newScript = "<script type='text/javascript' src='http://dataservice.com/getData?parm1=xx&parm2=xx'/>";
		 [scriptPlaceHolder.innerHTML] = newScript;
	

Windows Mobile 6 and Newer

Starting with Windows Mobile 6, IE Mobile allows you to dynamically create new nodes; therefore, you can programmatically create the <div> tag that holds the script rather than having to include the placeholder <div> tag in the HTML.

		 var [mySpecialDiv] = document.createElement("div");
		 [mySpecialDiv.id] = "mySpecialDiv";
		 var [bodyElementCollection] = document.getElementsByTagName("body");
		 var bodyElement = bodyElementCollection[0];
		 [bodyElement.appendChild(mySpecialDiv);]
	

		 var newScript = "<script type='text/javascript' src='http://dataservice.com/getData?parm1=xx&parm2=xx'/>";
		 [mySpecialDiv.innerHTML] = newScript;
	
Microsoft Communities