开发者

Mobile browser ignoring markup and script areas (Webkit, Android)

I'm working on web app (a C# MVC app) in which the view engine renders a different view page when it detects a mobile browser. In particular I'm targeting the Android web kit browser (on Froyo). Oddly the page does render correctly on the iPhone.

The problem is that when I test locally on the emulator it renders fine, and if I use Chrome on the desktop it renders fine... however, when I test on an actual phone (Nexus 1 and MyTouch) the markup is ignored and all text nodes are rendered as text. This happens using the HTML5 DOCTYPE (even using the simplest markup). If I insert an xmlns attribute into the tag (xmlns="http://www.w3.org/1999/xhtml") it will pay attention to the markup, but this come with it's own set of problems (most specifically it seems not to work with JQuery Moblie) and I'd much prefer to omit the namespace.

Also, just as a shot in the dark I explicitly set the content type to text/html to see if that would help, but no luck. I'm sure you all figured it out when I said开发者_JAVA技巧 I was writing this in C#, but the web server is IIS.

Even this simple markup doesn't work:

<html>
<head>
<title>html5 test for android</title>
</head>
<body>
<h1>h1 markup</h1>
<h2>h2 markup</h2>

<p>this is a paragraph of text</p>
</body>
</html>

I'm a newb in the mobile web dev arena - so I'm hoping this is such a simple and brainless issue it's something that everyone but me knows (which is why I'm not having any luck finding any direction on the web).

Thanks for any and all help!


Android web browsers should be able to make use of HTML5. The above code is just plain old HTML. You should put the HTML5 doctype in there as follows:

If that still doesn't work, I think you have some issues with the browser capability sniffing issue with ASP.NET. As for jQuery, if the browser can support HTML5, you might as well try to use the full blown jQuery. I know it works with the Android phone because I've tested it out on the Android simulator. Try looking into the ASP.NET browser capabilities first because it might have downgraded the browser capabilities of the Android webkit browser if ASP.NET cannot define what kind of browser and/or device it is dealing with. Other than that, you can try and write a non-server page (a plain HTML file) and see if that page renders correctly. Also, try using the regular jQuery 1.4.x rather than the mobile version.


The problem turned out to be the use of the mobile.browser file (from CodePlex). The file was indicating the server that the preferred mime type for my android browser was application/xhtml+xml rather than text/html. Setting the content type in the action method of the controller did not correct the problem. We ended up explicitly setting the content type in the page directive. We will probably revisit this solution to determine if the mobile.browser file is something we'll continue to use.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜