XHTML,JavaScript和CSS不兼容 [英] XHTML, JavaScript, and CSS incompatability

查看:104
本文介绍了XHTML,JavaScript和CSS不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用XHTML

和CSS开发非常符合标准的内容。我正在使用CSS定位,因此只需在我测试的浏览器中包含我的

样式表,以确保它们正确显示

。虽然格式化

并不漂亮,但页面是可读的,但是Netscape 4.x的浏览器如果我包含样式表使得它不可读,那么就会破坏定位

。我使用的是Eric Krok,Andy King,Michel Plungjan的

JavaScript浏览器嗅探器

http://www.webreference.com/ )确定我的用户使用什么浏览器

访问该页面并仅编写样式表链接如果

浏览器通过集合,如下:


if((is_mac&& is_ie5up)||(is_win&& is_ie6up)| | is_nav6up ||

is_opera7up || is_khtml || is_gecko){

var CSS = true;

} else {

var CSS = false;

}

if(CSS){

document.write(''< link href =" ; style.css" rel =" stylesheet"

type =" text / css" />'');

}

这似乎适用于linux上的konqueror。 Konqueror

会正确显示CSS,所以我希望它有链接到

样式表,但是konqueror拒绝写样式表链接。

显然,从我在其他地方读过的内容来看,这是因为在xhtml中使用javascript动态编写页面是无效的
,并且

konqueor是唯一的严格执行此操作的浏览器。


我想遵守标准,但现在不知道怎么做。我是

还遵守教育技术网络互操作性

标准称为SCORM,这阻止我使用服务器端

脚本来做浏览器检查。有没有其他人遇到这个问题?
问题?有没有人想出更好的解决方案?


谢谢,

Rob

解决方案

Rob Fentress写道:

我正在尝试使用XHTML
和CSS开发非常符合标准的内容。我正在使用CSS定位,因此只需要在我测试过的浏览器中包含我的
样式表,以确保它们正确显示。页面是可读的,没有CSS,虽然格式不是很好,但像Netscape 4.x这样的浏览器会破坏定位
如果我包含样式表,使其不可读。我使用的是Eric Krok的JavaScript浏览器嗅探器,Andy King,Michel Plungjan
http://www.webreference.com/ )确定我的用户访问该页面的浏览器,并且只有在
浏览器通过集合时才编写样式表链接,如下所示:


因此,禁用Javascript或碰巧使用浏览器的人你没有听到过
没有造型? CSS隐藏是一个既定的概念 - 不要

重新发明轮子。


< URL:http://w3development.de/css/ hide_css_from_browsers />

[snip]这似乎适用于Linux上的konqueror。 Konqueror
将正确显示CSS,所以我希望它有
样式表的链接,但konqueror拒绝编写样式表链接。
显然,从我在别处读到的,这个是因为在xhtml中使用javascript动态编写页面是无效的,而且konqueor是唯一严格执行此操作的浏览器。



[snip] ]


这是不正确的; Konqueror对XHTML没有任何线索。有一个关于这个问题的

公开错误报告:


< URL:http://bugs.kde.org/show_bug.cgi ?id = 52665>


-

Jim Dabell


谢谢你的帮助。


Jim Dabell< ji ******** @ jimdabell.com>在消息新闻中写道:< D - ******************** @ giganews.com> ...

Rob Fentress写道:

因此,禁用Javascript或碰巧使用您尚未听说过的浏览器的人没有造型? CSS隐藏是一个既定的概念 - 不要重新发明轮子。

< URL:http://w3development.de/css/hide_css_from_browsers/>


这些方法不够具体。他们隐藏了来自浏览器的CSS我不想隐藏它并允许它用于我不想要的浏览器

来使用它。主要关注的是所有

观众的内容都是可读的,其格式是次要的。因此,我更倾向于谨慎使用
错误,只是放弃使用我尚未测试过的浏览器的用户的极小百分比格式。

另外,我操作的上下文需要启用javascript

其他原因。
[snip]

这似乎适用于Linux上的konqueror。 Konqueror
将正确显示CSS,所以我希望它有
样式表的链接,但konqueror拒绝编写样式表链接。
显然,从我在别处读到的,这个是因为在xhtml中使用javascript动态编写页面是无效的,而且konqueor是唯一严格执行此操作的浏览器。


[snip]

这是不正确的; Konqueror对XHTML没有任何线索。有一个关于这个问题的公开错误报告:

< URL:http://bugs.kde.org/show_bug.cgi?id = 52665>



是的。事实证明我误解了这个问题。 CSS

在konqueror中工作的原因是我在一个外部

javascript中设置了一个变量,这是一个标志,指示是否写入链接到

样式表。当在第二个外部JavaScript中,我使用那个

变量来确定是否写入链接时,它总是被评估为false,因为它超出了范围。虽然在所有其他

浏览器中工作过。奇怪。


Rob


Jim Dabell< ji ******** @ jimdabell.com>在留言新闻中写道:< D - ******************** @ giganews.com> ...


所以Javascript被禁用或碰巧使用浏览器的人你没有听说过没有造型? CSS隐藏是一个既定的概念 - 不要重新发明轮子。

< URL:http://w3development.de/css/hide_css_from_browsers/>




但真正的问题是,这些主要是针对特定浏览器特性的黑客攻击。如果,在下一个

版本的禁止浏览器中,他们修复了你的b / b $ b $取决于阻止CSS的特性,但他们并没有修复实际情况问题

与CSS?如果一个新的浏览器出来不支持

CSS怎么样但你也没有特权依赖

来阻止CSS?我理解不依赖于javascript和

的愿望,即使用基于javascript的浏览器检查器继续工作所需的无限(尽管不经常)更新,但我我认为使用黑客攻击是更好的问题。 IMO,最好给他们一个

可读的无格式页面并告诉他们打开javascript并获得更好的浏览器

。实际上,最好使用javascript中除了javascript之外的hack来处理浏览器欺骗问题。

重要的是要小心谨慎(不读CSS)。


Rob


I am trying to develop very standards-compliant content using XHTML
and CSS. I am using CSS positioning and thus need to only include my
stylesheet on browsers I have tested to make sure they display
correctly. The page is readable without the CSS though the formatting
is not pretty, but browsers like Netscape 4.x bungle the positioning
if I include the stylesheet, making it unreadable. I am using the
JavaScript Browser Sniffer by Eric Krok, Andy King, Michel Plungjan
(http://www.webreference.com/) to determine what browser my users are
accessing the page with and only writing the stylesheet link if the
browser passes muster, as follows:

if ((is_mac && is_ie5up) || (is_win && is_ie6up) || is_nav6up ||
is_opera7up || is_khtml || is_gecko) {
var CSS = true;
} else {
var CSS = false;
}
if (CSS) {
document.write(''<link href="style.css" rel="stylesheet"
type="text/css"/>'');
}

This seems to work on everything but konqueror on linux. Konqueror
will display the CSS properly, so I want it to have the link to the
stylesheet, but konqueror refuses to write the stylesheet link.
Apparently, from what I have read elsewhere, this is because it is
invalid in xhtml to write the page on the fly with javascript, and
konqueor is the only browser that strictly enforces this.

I want to comply with the standards, but don''t know how to now. I am
also complying with an educational technology web interoperability
standard called SCORM, and this prevents me from using server-side
script to do the browser check. Has anyone else encountered this
problem? Has anyone come up with a better solution?

Thanks,
Rob

解决方案

Rob Fentress wrote:

I am trying to develop very standards-compliant content using XHTML
and CSS. I am using CSS positioning and thus need to only include my
stylesheet on browsers I have tested to make sure they display
correctly. The page is readable without the CSS though the formatting
is not pretty, but browsers like Netscape 4.x bungle the positioning
if I include the stylesheet, making it unreadable. I am using the
JavaScript Browser Sniffer by Eric Krok, Andy King, Michel Plungjan
(http://www.webreference.com/) to determine what browser my users are
accessing the page with and only writing the stylesheet link if the
browser passes muster, as follows:
So people with Javascript disabled or happen to use a browser you haven''t
heard of get no styling? CSS hiding is an established concept - don''t
reinvent the wheel badly.

<URL:http://w3development.de/css/hide_css_from_browsers/>
[snip] This seems to work on everything but konqueror on linux. Konqueror
will display the CSS properly, so I want it to have the link to the
stylesheet, but konqueror refuses to write the stylesheet link.
Apparently, from what I have read elsewhere, this is because it is
invalid in xhtml to write the page on the fly with javascript, and
konqueor is the only browser that strictly enforces this.


[snip]

That''s incorrect; Konqueror doesn''t have a clue about XHTML. There''s an
open bug report relating to this issue:

<URL:http://bugs.kde.org/show_bug.cgi?id=52665>

--
Jim Dabell


Thanks for your help.

Jim Dabell <ji********@jimdabell.com> wrote in message news:<D-********************@giganews.com>...

Rob Fentress wrote:
So people with Javascript disabled or happen to use a browser you haven''t
heard of get no styling? CSS hiding is an established concept - don''t
reinvent the wheel badly.

<URL:http://w3development.de/css/hide_css_from_browsers/>

Those methods are not specific enough. They hide css from browsers I
don''t want to hide it from and allow it for browsers that I don''t want
to use it. The main concern is that the content be readable for all
viewers, its formatting being secondary. Therefore, I would prefer to
err on the side of caution and just ditch the formatting on the
miniscule percentage of users who are using browsers I haven''t tested.
Also, the context I am operating in requires javascript to be enabled
for other reasons.

[snip]

This seems to work on everything but konqueror on linux. Konqueror
will display the CSS properly, so I want it to have the link to the
stylesheet, but konqueror refuses to write the stylesheet link.
Apparently, from what I have read elsewhere, this is because it is
invalid in xhtml to write the page on the fly with javascript, and
konqueor is the only browser that strictly enforces this.


[snip]

That''s incorrect; Konqueror doesn''t have a clue about XHTML. There''s an
open bug report relating to this issue:

<URL:http://bugs.kde.org/show_bug.cgi?id=52665>


Yes. It turns out I misdiagnosed the problem. The reason the CSS
wasn''t working in konqueror is that I set a variable in one external
javascript that was a flag indicating whether to write the link to the
stylesheet. When, in a second external javascript, I used that
variable to determine whether to write the link, it was always
evaluated to false, because it was out of scope. Worked in all other
browsers though. Strange.

Rob


Jim Dabell <ji********@jimdabell.com> wrote in message news:<D-********************@giganews.com>...


So people with Javascript disabled or happen to use a browser you haven''t
heard of get no styling? CSS hiding is an established concept - don''t
reinvent the wheel badly.

<URL:http://w3development.de/css/hide_css_from_browsers/>



But the real problem is that those are mostly hacks that are dependent
on the peculiarties of particular browsers. What if, in the next
version of the prohibited browser, they fix the peculiarity that you
are depending on to block CSS, but they don''t fix the actual problem
with the CSS? What if a new browser comes out that doesn''t support
CSS well but also doesn''t have a peculiarity that you are depending on
to block CSS? I understand the desire to not depend on javascript and
the unending (though infrequent) updating that is required to make a
javascript-based browser checker continue to work, but I think there
are greater problems using hacks. IMO, it is better to give them a
readable unformatted page and tell them to turn on javascript and get
a better browser. Actually, it is probably best to use the hacks in
addition to the javascript to deal with issues of browser spoofing.
The important thing is to err on the side of caution (read no CSS).

Rob


这篇关于XHTML,JavaScript和CSS不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆