用于Windows Phone 7的CSS

nee*_*eKo 6 html css windows-phone-7

我正在尝试添加一个针对Windows Mobile的.css文件,并且media="handheld"对于此设备没有任何帮助,我已按照官方Windows Phone网站的说明进行操作,总结如下:

<!--[if IEMobile 7]>
<p>Welcome to Internet Explorer Mobile.</p>
<![endif]-->
<![if !IEMobile 7]>
<p>All other browsers</p>
<![endif]>
Run Code Online (Sandbox Code Playgroud)

问题

正如预期的那样,在Firefox和桌面版的Internet Explorer中,它显示了它应该:"所有其他浏览器".

不幸的是,我的Windows Phone 7还显示"所有其他浏览器".我在条件评论中尝试使用和不使用"7",结果相同.

我的.html中没有任何其他内容可能导致问题,因为我正在对此进行测试:

<html>
    <body>
        <p>Does work</p>
        <!--[if IEMobile 7]>
            <p>Welcome to Internet Explorer Mobile.</p>
        <![endif]-->
        <![if !IEMobile 7]>
            <p>All other browsers</p>
        <![endif]>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

这个的在线版本暂时在这里.

我复制粘贴官方网站上的代码,我在WP7上的Internet Explorer设置指定移动版本作为首选版本.我也有芒果更新.

perishablepress.com文章中,我读到media="Screen"在正常的非手持式样式表声明中指定(大写S)将迫使WP7使用media="handheld"声明,但这对我不起作用.


有没有人有使用.css定位WP7的经验?如果是,您的解决方案是什么?

请记住,我真的在寻找如何让WP7选择.css的移动版本,而不是如何解决条件评论问题.感谢您的时间!

编辑

我已经添加了一个javascript(谢谢w3schools.com)来询问浏览器信息(使用'navigator'),这是我的设备(Samsung Omnia,btw):

Does work
All other browsers
Browser CodeName: Mozilla
Browser Name: Microsoft Internet Explorer
Browser Version: 5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7)
Cookies Enabled: true
Platform: Win32
User-agent header: Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7)
Run Code Online (Sandbox Code Playgroud)

key*_*rdP 10

芒果运行IE9,而不是IE7.你的支票说,if not IEMobile 7, display 'All other browsers'.由于浏览器是IE9,All other browsers因此显示.

编辑 - 您可以尝试使用Javascript来检测它.我从这里改编了这段代码.

browserUA = navigator.userAgent.toLowerCase();
if (browserUA.search('windows phone os 7') > -1)
   //windows phone therefore load WP CSS file
else
   //it's some other browser
Run Code Online (Sandbox Code Playgroud)

当然,用户代理可以很容易地更改,因此出于安全原因不要使用此方法.但是,对于Windows Phone检测,它应该工作.