Posts tagged with "Firefox"
测试3种浏览器对打印表格的支持程度
Friday, November 4, 2005 5:36:37 AM
- 先看这个测试页
- http://my.opera.com/tifa/homes/files/table_print.html
- 这是一个有thead、tfoot、tbody元素和打印分页样式的表格。。
- 英文稍好的可以看W3C的这段文档:
- http://www.w3.org/TR/REC-html40/struct/tables.html#edef-THEAD
- 摘要:
Table rows may be grouped into a table head, table foot, and one or more table body sections, using the THEAD, TFOOT and TBODY elements, respectively. This division enables user agents to support scrolling of table bodies independently of the table head and foot. When long tables are printed, the table head and foot information may be repeated on each page that contains table data.
简单来说,根据W3C HTML 4.0的规范,thead和tfoot是表头和表脚,它们始终出现在表格内容的头尾部。当一个很长的表格需要分页打印时,表头和表脚应该始终出现在每一页表格的头尾部。
现在我测试一下3种浏览器(Microsoft Internet Explorer、Opera、Mozilla Firefox)对这个规范的遵守程度:
在通常模式下浏览,三种浏览器几乎没有分别,它们都遵守了thead和tfoot始终在表格头尾的规范。但当我试图打印这个表格时问题出现了。
- 当一个表格很长,必须要分页显示时,Opera的表尾显示非常奇怪,显然这是一个BUG。
- 不论你是否加上强制分页的样式(page-break-after:always;),IE和Opera都没有遵守表头和表脚出现在所有分页表格头尾部的规定。而是直接把表格从中截断,头尾分别在第一页和最后一页。
- Firefox必须在要分页的位置加上分页的样式头尾才会出现在下一页,否则除了第一页和最后一页,其他页面都只能显示表头,如果仔细观察尾部,会发现表尾其实是被“隐藏”了,只能看到字的一小部分。BUG?
- Opera居然不支持打印时的分页属性(page-break-after:always;),这让我大跌眼镜。要知道,这个东西就连古老的IE5都支持。
- 当用CSS设定边框合并的时候(border-collapse:collapse;)除第一页外所有分页表格的最上方都缺少了一个边框,显然这个边框被截断到了上一页,这个问题三个浏览器同时存在。虽然符合标准,但我认为这是浏览器不够智能,测试时也不够细心所致。
- Opera不支持打印时的颜色定义,原本红色的字变成了黑色,见前面的截图。
结论就是,三种浏览器都不尽如人意,Firefox相对表现最好,基本实现了W3C标准,IE除了没有实现thead和tfoot外表现也算正常,Opera的表现最差。
[转载]如何使.net开发的程序正确支持firefox等非ie浏览器
Wednesday, October 26, 2005 2:36:18 AM
http://dev.codelphi.com/virushuo/archive/2004/08/27/20311.aspx
本文的完成,需要感谢adex的帮助。
用firefox去看asp.net做的网站,一般是很不爽的。所有的内容都像被风吹晕了一样往左边斜。就像这样:

IE里面则是这样的:
以前我并没有在意过这个问题,总觉得是作页面的时候做得不好。(关于页面的知识我很bc,就算在意估计也不会有什么结果)。今天,同事Adex发现了这个 现象的原因--asp.net的服务器控件在不同的浏览器中render出来的结果是不一样的。在firefox和ie中分别是这样的:
- firefox:
-
<table id="panLogin" cellpadding="0" cellspacing="0" border="0" width="100%"> - ie:
<div id="panLogin">
这下清楚了,本来好好的div,在firefox中变成了table。怪不得无论如何都往左偏。
- 用Reflector反编译system.web.dll的代码,在HtmlTextWriter类中可看到如下代码:
protected virtual HtmlTextWriterTag GetTagKey(string tagName)
{
if ((tagName != null) && (tagName.Length > 0))
{
object obj1 = HtmlTextWriter._tagKeyLookupTable[tagName.ToLower(CultureInfo.InvariantCulture)];
if (obj1 != null)
{
return ((HtmlTextWriterTag) obj1);
}
}
return HtmlTextWriterTag.Unknown;
}- 这段代码在其子类Html32TextWriter中被重载为
protected override string GetTagName(HtmlTextWriterTag tagKey)
{
if (tagKey == HtmlTextWriterTag.Div)
{
return "table";
}
return base.GetTagName(tagKey);
}
明显,div被替换成了table。
- 为什么如此呢?请看这两篇文章
- http://aspnet.4guysfromrolla.com/articles/050504-1.aspx
- http://slingfive.com/pages/code/browserCaps/
比较长,我就不翻译了。
- 简单的说,就是在machine.config里面的<browserCaps>节点,定义了一些判断useragent的表达式。其中对ie的判断是这样的:
<case match="^Mozilla[^(]*\(compatible; MSIE <snip>">
browser=IE
...
tagwriter=System.Web.UI.HtmlTextWriter
</case>- 而对mozilla5/firefox呢?是这样的:
<case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+ )?Netscape6/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)).*">
首先,这段正则表达式错了,firefox和mozilla5的useragent都没有包含Netscape6。然后,这段代码也没有让他们使用 HtmlTextWriter。也就是说,mozilla5/firefox只能得到html3.2的代码。
- 解决的方法很简单,用这个老外写的代码就可以,不仅解决了firefox的问题,好像还能解决mac机上的问题,不过我没测试mac。代码如下:
<!-- 2003-12-03, Rob Eberhardt - http://slingfive.com/demos/browserCaps/ -->
<browserCaps>
<!-- GECKO Based Browsers (Netscape 6+, Mozilla/Firebird, ...) //-->
<case match="^Mozilla/5\.0 \([^)]*\) (Gecko/[-\d]+)? (?'type'[^/\d]*)([\d]*)/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*)).*">
browser=Gecko
type=${type}
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
<case match="rv:(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'\w*))">
version=${version}
majorversion=${major}
minorversion=${minor}
<case match="^b" with="${letters}">
beta=true
</case>
</case>
</case>
<!-- AppleWebKit Based Browsers (Safari...) //-->
<case match="AppleWebKit/(?'version'(?'major'\d)(?'minor'\d+)(?'letters'\w*))">
browser=AppleWebKit
version=${version}
majorversion=${major}
minorversion=0.${minor}
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
<case match="AppleWebKit/(?'version'(?'major'\d)(?'minor'\d+)(?'letters'\w*))( \(KHTML, like Gecko\) )?(?'type'[^/\d]*)/.*$">
type=${type}
</case>
</case>
<!-- Konqueror //-->
<case match = "Konqueror/(?'version'(?'major'\d+)(?'minor'\.\d+)(?'letters'));\w*(?'platform'[^\)]*)">
browser=Konqueror
version=${version}
majorversion=${major}
minorversion=${minor}
platform=${platform}
type=Konqueror
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
</case>
</browserCaps>
为了避免在每台机器上配置的麻烦,可以在项目的web.config中加入这段代码。试试看,是不是table变成div了?
题外话:这个错误有点弱智,我不太相信ms能犯这样的错误,其实我更倾向于相信这是故意的。要么就是他们真的认为除了IE,别的浏览器都不能正确的支持html4.0。殊不知,支持最差得反而是IE。
英文网站提到这个问题的很多,但中文的竟然一个没有。这是一件可怕的事情,可见中国的.net程序员眼中只有IE,没有其他浏览器。这是何等悲哀的事情。
Friends (3)
Latest comments
-

anonymous
Анонімний writes: Different people in all countries take th ...
-

anonymous
Анонімний writes: Make your own life time more simple take ...
-

anonymous
Анонімний writes: I think that to get the mortgage loans fr ...
-

anonymous
Анонімний writes: That's well known that cash makes people ...
-

anonymous
Анонимно writes: Different people in the world get the cred ...
-

anonymous
Анонімний writes: высококвалифицированный сантехник киев то ...
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
| ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | |||
LINKS
-
Peki's Space
虎MM的BLOG,无限122~
-
喜欢秋天
老姐的BLOG
-
薰の丝米空间
黄小强的BLOG
-
零度高烧
蒋郁的BLOG
-
Tifa吧
喜欢Tifa不?喜欢就进!
-
web.Frontend
想系统学习xhtml css的人必看
-
Andy's Blog
小毅
-
π.ε.ρ.ι.π.ε.τ.α.
佳佳
-
Satellite of Love
陈力











