IEMobile Team Weblog

Information about Internet Explorer for Windows Mobile

Customizing IE Mobile with User Stylesheets

IE Mobile has supported installable user stylesheets ever since Windows Mobile 2003.  User stylesheets provide a powerful way for you to customize the web browsing experience—one of the core features of CSS.  For more information on user stylesheets and the “cascade” part of Cascading Style Sheets, see http://www.w3.org/TR/REC-CSS1#the-cascade. (Note that the spec refers to “reader” stylesheets whereas I prefer the term “user”.  For the sake of this article, consider them as synonymous terms).

 

Let’s use an example to demonstrate how you can use this feature of IE Mobile.  IE Mobile has a Show Images feature, whereby you can turn off the downloading and display of images on the page.  This can speed up page load times and reduce the amount of data you download over your slow (and possibly expensive) cellular connection.  Instead of the image, you see the placeholder image and the text in the image’s ALT attribute, if there is any text.  Like this:

 

Now I’m going to be honest with you—I’m not crazy about how this looks.  The placeholder image and alt text take up valuable screen real estate without much benefit.  We are reviewing improving this feature for a future release—perhaps we just remove the placeholder image and still display the ALT text.  For now let’s use a user stylesheet to turn off display of images altogether.

 

We are going to install a stylesheet that has one simple rule:

 

img { display:none !important }

 

This turns off the display of img elements altogether, and IE Mobile knows to not download an image if the element’s display property is set to none.  The !important ensures that this rule will trump any author rules that set the display property of images.

 

Let’s name this file noimages.css and put it in the \windows directory of the device.

 

The next step is to tell IE Mobile to load this style sheet.  When the browser app starts, it enumerates the following registry key for user style sheets:

 

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Stylesheet

 

Every subkey under this represents a style sheet to load.  Each subkey must have the following values:

 

  • “Enabled” – a REG_DWORD value indicating if this style sheet should be loaded or not.  Set it to 1 to have your style sheet loaded.
  • “File” = a REG_SZ value containing the path to the style sheet

 

For our example, the necessary registry entries would look like this:

 

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Stylesheet\NoImages

Enabled = 1

File = “\windows\noimages.css”

 

There is one last requirement if you are doing this for Windows Mobile 5.0.  For security reasons, the SYSTEM attribute must be set on the style sheet file (\windows\noimage.css in this example). This can be done by setting the SYSTEM attribute on the file on your desktop, and then copying the file to the device via trusted install (more on that below). 

 

If the browser app is already running, you will have to terminate the browser app and re-start it for the new style sheet to take effect.  On PocketPC, Ctrl-Q will end IE Mobile, and on Smartphone you can turn the phone off and then back on.

The end result looks like this:

 

That’s it.  A fairly simple process for a powerful tool to affect the way the browser presents pages.  As an example of this power, our One Column view in the browser is implemented almost entirely with a style sheet (we had to add a little extra code to remove spacer images). 

 

If you come up with a style sheet you’d like to distribute, you’ll probably want to create a CAB file for app install that will place the style sheet (with the SYSTEM attribute set) on the device, and modify the registry as explained above.  You can read more about how to do this at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/guide_ppc/html/ppc_wce51conapplicationinstallationozup.asp

 

Randy Ramig

August 8, 2006 Addendum:  Your CSS file must be stored as Unicode.  You can do this by opening it up in notepad and saving it as Unicode.

Published Wednesday, March 15, 2006 5:31 PM by iemoblog

Comments

 

Zandoná Mobile® said:

I have been asked about AJAX development support for Internet Explorer Mobile (running on Windows Mobile-based...
May 3, 2006 10:29 AM
 

Shangwu said:

Thanks for the information. I followed your instuction to create the css file and registry key on my Axim V51v (Windows Mobile 5). Nothing is changed. The IE still shows image spaces.
Is Pocket IE same as IE Mobile?
July 21, 2006 3:14 PM
 

iemoblog said:

Shangwu - does your file actually have the system bit set on the file itself?  That's the leading cause of failure here that I can think of, if you followed all the other instructions perfectly.

IE Mobile is the current revision of the browser.  Pocket IE was the old browser, and we generally use it to refer to old devices/builds out there (pre-Windows Mobile 5.0) as well as the official "pocket IE" that was included in Platform Builder (Windows CE embedded) for those needing a tiny browser for help files or very, very small footprint devices.

-Cameron
July 21, 2006 4:06 PM
 

Shangwu said:

Cameron,

Thank you for quick response. Yes, I set the file's attribute as system. Is there any way I can verify that the style sheet is loaded or not by IE? Does the subkey name is case sensitive like StyleSheet or Stylesheet?
July 21, 2006 4:16 PM
 

iemoblog said:

The subkey names are not case sensitive.

I'd try a very simple stylesheet and make sure it gets loaded first, just to validate that you don't have any problems with your desired stylesheet.

The only easy way of verifying success is visually on the page (or programmatically on the page, but that's work!)

You can't just copy the file over from ActiveSync, either - it does have to be installed as directed in the article, or that system bit will be stripped in the desktop->device transfer process.  You could also use a utility, or write a small app to actually change the attribute on the device itself.
July 24, 2006 5:48 PM
 

Shangwu said:

I use a utility called Total Commander to copy the CSS file to \Windows folder and set the system attribute of the file.

Here is the registry values and the file content:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Stylesheet\NoImages]
"Enabled"=dword:00000001
"File"="\\Windows\\noimages.css"


noimages.css

 IMG { display: none !important }

Probably Dell changed the IE Mobile's code to not load user stylesheets.

Thanks.

July 25, 2006 9:52 AM
 

Randy Ramig said:

Did you re-start the browser?  The style sheets are loaded at app initialization time.
Best thing to try is a reboot and see if that helps.

Randy
July 25, 2006 6:03 PM
 

Shangwu said:

Noop, reboot doesn't help.
Is it possible to download a standard IE Mobile from somewhere and install it on my PPC?

Thanks for continuing input.
July 26, 2006 9:29 AM
 

iemoblog said:

Shangwu - sort of is the answer.  You can download the SDK for Windows Mobile, and that includes the device emulator.  There are stock images of a Smartphone and a PPC in the SDK which can be loaded into the emulator, on the desktop, and those contain IE Mobile.  It's a fairly painless process.

Pocket PC SDK here: http://www.microsoft.com/downloads/details.aspx?FamilyID=83A52AF2-F524-4EC5-9155-717CBE5D25ED

Smartphone SDK here: http://www.microsoft.com/downloads/details.aspx?familyid=DC6C00CB-738A-4B97-8910-5CD29AB5F8D9

Either one may prove easier for development and testing than repeated pecking away at the device.  We utilize the same tools internally for that.  Those SDKs also contain documentation as well as support links.

Another tool I use, which will speed things along, is some kind of "remote" tool for your device.  We have a power-toy remote viewer floating around the Microsoft download section, or there are great third party add-ons that do all this and more.  We even use some of them ourselves!  It really helps with configuration and editing because lots of keyboard inputing and the small screen size can be hard on a developer working for hours on end.

-Cameron
July 26, 2006 12:36 PM
 

Shangwu said:

Today I followed the instruction to set everything on an WM5 emulator without success. I created an application to set system attribute on to the css file.
Would you please to double check your instruction to make sure all registry key names are acurate? I tried both stylesheet and stylesheets without success.

Regards.
July 26, 2006 7:11 PM
 

Randy Ramig said:

Hi Shangwu, I'm sorry you're having problems with this.  Could you please put the css file and tools in a cab file and send them to iemoblogpierox@pieroxmicrosoft.com so that we can take a look?

(remove the instances of "pierox" from the above address, it is there to prevent spam)

Randy
July 28, 2006 11:39 AM
 

Shangwu said:

Hi Randy,

I have sent a zip including a CSS file, a REG file and the utility Total Commander to the email address. Please let me know if you could not receive it.

Thanks,
Shangwu
July 28, 2006 3:19 PM
 

iemoblog said:

Hi Folks:

I found out the issue that some of you have been having with this.  The CSS file must be in Unicode.  For example, on Windows XP open the file with notepad and Save As and select Unicode.

I'll update the blog entry, please post back if this did or did not fix the issue.

Randy
August 8, 2006 7:26 PM
 

sank said:

Is it possible to remove the rubberbanding selection that happens when anchor elements get focus?
August 21, 2006 10:24 PM
 

iemoblog said:

Sorry, there is no way to prevent the selection rectangle. What are you up to? Maybe we can make another recommendation.

-Steve
August 22, 2006 11:46 AM
 

sank said:

I'm trying to provide background color highlighting on selection using A:focus css instead of the rubberbanding.
August 24, 2006 11:47 AM
 

iemoblog said:

Hi sank:

We have a CSS extended property called "x-focus-border".  You can set it to "none" to get rid of the focus border.  For example:

a:focus {x-focus-border:none}

By the way, we recognize that this extension probably should have been named -ms-focus-border per the CSS 2.1 spec on vendor extensions.  We'll keep that in mind in the future.

-Randy
August 24, 2006 12:52 PM
 

sank said:

Thanks Randy :-)

That  worked. But had to put the x-focus-border in the a:link block instead of the a:focus. This was on a treo 700w OS 5.1.195

What are the other options possible for x-focus-border?
August 28, 2006 5:08 PM
 

Defcon said:

Hye all! I need to dig more details infomation regarding this IE Mobile browser. I already make a lot of search via major search engine either Microsoft.com but i didnt fint what i need it. What i need is a browser details such as:

- what a flash version did currently default on IE Mobile browser

-Is that IE Mobile browser support PNG transparent background such as on IE 7?

Any referrer link or base on experience surf with that Windows Mobile 5.0?

March 24, 2007 4:54 AM
 

iemoblog said:

I'm not sure what you are asking regarding "a flash version". On recent versions, you can type "about:version" into the address bar to see what version of the browser is installed.

Yes, IE Mobile supports transparent PNGs.

Again, I'm not sure what you are asking in your last question.

-Steve

April 2, 2007 2:49 PM
 

prc said:

Any way to use CSS to control other IE Mobile display options, such as full screen and zoom?

April 12, 2007 12:35 PM
 

iemoblog said:

prc,

No, CSS can't be used for that.

-Steve

April 12, 2007 5:41 PM
 

gilbertw said:

Is there more information on "One Column" view mode, its associated style sheet, and how it can be implemented in an browser control object?

October 25, 2007 2:54 PM
 

iemoblog said:

gilbertw:

We have not published the details of the One Column CSS since it is internal to the product.  We essentially apply "!important" styles to force margins to a small size and tables into block elements.

You can apply styles to a control using DTM_ADDSTYLE: http://msdn2.microsoft.com/en-us/library/bb159689.aspx

-Charles

October 26, 2007 5:48 PM
 

dbirk said:

Is there any way to hide the address bar in IE Mobile? This used to be a feature in Pocket IE. We use Symbol MC9090s and access an SAP generated web site. Any way to hide the address bar??

Thanks in advance!

Douglas Birk

December 1, 2007 12:06 PM
 

iemoblog said:

dbirk:

In IE Mobile, we only support hiding the address bar using the full screen mode (which hides the softkeys as well).  

December 3, 2007 6:56 PM
 

IEMobile Team Weblog Customizing IE Mobile with User Stylesheets | Paid Surveys said:

May 29, 2009 5:47 PM
 

Using the webbrowser control in Windows Mobile « Archis's Blog said:

June 15, 2009 9:45 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker