Firefox中的Javascript问题 [英] Javascript problem in Firefox

查看:57
本文介绍了Firefox中的Javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 - 我正在尝试使用Javascript将材料放入表格中

(即与之前的材料一起)如果用户的屏幕尺寸为

足够大如果不是这样的话,请在表格下方(表格下方)。


以下代码(标签属性和其他无关材料

已移除)在IE中有效但不是Firefox:

< table>

< tr>< td>

第一套材料

< / td>

< script language =" text / javascript">

<! -

if ((screen.width> = 1024)&&(screen.height> = 768))

{

document.write("< td>" ;);

}

其他

{

document.write("< / tr>< ; / table>");

}

< / script>

第二套材料

< script language =" text / javascript">

<! -

if((screen.width> = 1024)&a熔点;&安培; (screen.height> = 768))

{

document.write("< / td>< / tr>< / table>") ;

}

< / script>


如果您查看来源在Firefox中,您可以看到它将

视为单个脚本,只有第一个打开脚本

标记和第二个关闭脚本标记以紫色突出显示。


有人可以帮忙吗?


谢谢!


Karin

PS

这是它为高分辨率制作的效果

屏幕:

< table>

< tr>< td>

第一套资料到这里

< / td>

< td>

第二组材料在这里进入表格

< / td>< / tr>< / table>


对于低价格:

< table>

< tr>< td>

第一套材料到这里

< / td>

< / tr>< / table>

第二套材料在桌子外面

解决方案




Karin Jensen wr注意:

< script language =" text / javascript">
使用

< script type =" text / javascript">



< script language ="的JavaScript" type =" text / javascript">

<! -
^^^^

只需删除它,或者如果您认为有任何需要注释掉

脚本代码然后正确执行并插入评论更接近

// - > < / script>


收盘前的
< / script> ;.

-


Martin Honnen
http://JavaScript.FAQTs.com/




" Karin Jensen" < k _ ****** @ mailblocks.com>在消息中写道

新闻:Pine.GSO.4.44.0508311550280.21034-100000@austen ...

嗨 - 我正在尝试使用Javascript将材料放入表格<如果用户的屏幕尺寸足够大并且在表格下方(在桌子下面),如果它不是。



实际上你的脚本存在coupla基本问题,可能或者b / b
可能不会导致问题 - 但首先修复它们应该是优先考虑

只是为了让他们脱离嫌犯名单。 ; ^)


可能还有其他人,但我最开始看到的是:


1)你有语言属性与类型混淆属性。

更改语言= QUOT;文本/ JavaScript的" "到类型= QUOT;文本/ JavaScript的" " ;.你好b / b
很乐意不包括语言属性。


2)你的隐藏评论被打破 - 你开始评论

("<! - ")但永远不会结束它们(" // - >")。这可能会导致您在FireFox中看到的

颜色编码问题(这是一个猜测)。就我个人而言,b $ b会完全删除这些评论 - 这是一种古老的技巧

今天真的没有提供任何东西(虽然我会承认它'''一个很难的习惯

打破)。


修复这些并看看你在哪里。


最后,和我在这里为这里的哲学打扮道歉(请随意给我b $ b忽略我),一些想法:


我认为你的概念是有缺陷的。你不希望屏幕尺寸 - 你想要浏览器尺寸。假设用户总是最大限度地运行他们的浏览器是错误的...即使浏览器最大化了

屏幕房地产对于网页被工具栏削减,

浏览器栏,搜索栏,收藏栏和糖果棒。


屏幕尺寸之间有很强的相关性和浏览行为:

低屏幕分辨率的用户几乎总是最大化他们的浏览器,

具有很高屏幕分辨率的用户很少这样做。然而,具有高屏幕分辨率的用户屏幕分辨率也更有可能让房地产吞噬

界面元素也可见。


无论如何,获得浏览器大小的一种方法是(

浏览器显示区域的实际大小)是检查当前BODY的大小。标签

(这个代码,当然,还有可以检查的身体标签):


document.getElementsByTagName(''BODY'') [0] .clientHeight

document.getElementsByTagName(''BODY'')[0] .clientWidth


我只在IE 6上测试了这个.x和FireFox 1.x ......它可能也可能不起作用

其他人。


当然只是因为他们的浏览器在这个尺寸上是没有理由

假设他们会在会话期间留下那么大的数量。

你的实现应该能够处理这种行为 - 非常

如果你只是在
检查了那个状态,那么该网站的内容不应该对浏览器当前状态的假设有任何假设。
会议开始。


再次,对讲座感到抱歉。我是一名人工因素顾问,所以

这种东西会回家。 ; ^)


无论如何我希望这会有所帮助,


Jim Davis


< blockquote>Jim Davis <是ne ******** @ vboston.com>写道:

document.getElementsByTagName(''BODY'')[0] .clientHeight


为什么这种令人费解的获取文档的方式。身体?我不认为

有一个浏览器实现document.getElementsByTagName而不是

document.body(document.body由IE 3实现)都属于

W3C DOM 1级HTML标准)。


clientHeight属性未标准化(由IE引入

4) ,它在身体元素上的位置也不是。如果想要找到浏览器文档视口的

大小,常见问题解答有更多通用的方式

:< URL:http:// jibbering.com/faq/#FAQ4_9>

当然只是因为他们的浏览器在这个大小的STARTS没有理由认为他们会在他们的持续时间内留下那么大的会话。




啊,是的。魔鬼也在细节中。

至少,在页面加载后,用户可以看到他正在做什么

调整它的大小。


/ L

-

Lasse Reichstein Nielsen - lr * @ hotpop.com

DHTML死亡颜色:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>

''信仰没有判断只会降低精神神圣。''


Hi - I am trying to use Javascript to put material inside a table
(i.e. alongside the previous material) if the user''s screensize is
big enough and outide the table (beneath table) if it isn''t.

The following code (tag properties and other extraneous material
removed) works in IE but not Firefox:
<table>
<tr><td>
first set of material
</td>
<script language="text/javascript">
<!--
if ((screen.width>=1024) && (screen.height>=768))
{
document.write("<td>");
}
else
{
document.write("</tr></table>");
}
</script>
second set of material
<script language="text/javascript">
<!--
if ((screen.width>=1024) && (screen.height>=768))
{
document.write("</td></tr></table>");
}
</script>

If you "view source" in Firefox, you can see that it is treating
this as a single piece of script, with only the first opening script
tag and second closing script tag highlighted in purple.

Can anybody help?

Thanks!

Karin

P.S.
This is the effect it''s meant to produce for high resolution
screens:
<table>
<tr><td>
first set of material goes here
</td>
<td>
second set of material goes here inside table
</td></tr></table>

And for low ones:
<table>
<tr><td>
first set of material goes here
</td>
</tr></table>
second set of material goes here outside table

解决方案



Karin Jensen wrote:

<script language="text/javascript"> Use
<script type="text/javascript">
or
<script language="JavaScript" type="text/javascript">
<!-- ^^^^
Simply remove that, or if you think there is any need to comment out
script code then do it properly and insert the comment closer
//--> </script>


before the closing </script>.
--

Martin Honnen
http://JavaScript.FAQTs.com/



"Karin Jensen" <k_******@mailblocks.com> wrote in message
news:Pine.GSO.4.44.0508311550280.21034-100000@austen...

Hi - I am trying to use Javascript to put material inside a table
(i.e. alongside the previous material) if the user''s screensize is
big enough and outide the table (beneath table) if it isn''t.



There are actually a coupla basic problems with your script which may, or
may not be causing the problems - but fixing them first should be a priority
just to get them off the suspects list. ;^)

There may be others but what I see off the top of my head is:

1) You''ve got the "language" attribute mixed up with the "type" attribute.
Change " language="text/javascript" " to " type="text/javascript" ". You
can happily not include the "language" attribute at all.

2) Your "hiding" comments are broken - you''re beginning the comments
("<!--") but never ending them ("// -->"). This is probably causing the
color-coding issues you''re seeing in FireFox (that''s a guess). Personally I
would remove the comments completely - it''s an archaic technique that
doesn''t really offer anything today (although I''ll admit it''s a hard habit
to break).

Fix those and see where you are.

Lastly, and I apologize in advance for waxing philosophic here (feel free to
ignore me), some thoughts:

I think that you''re concept is flawed. You don''t want the screen size- you
want to the browser size. It''s wrong to assume that the user will always
run their browser maximized... and even if the browser were maximized the
screen real-estate useful for a web page is whittled away by tool bars,
explorer bars, search bars, favorites bars and candy bars.

There''s a strong correlation between screen size and browsing behavior:
users with low screen resolutions nearly always maximize their browsers,
users with very high screen resolutions rarely do. However users with high
screen resolutions are also much more likely to leave real-estate gobbling
interface elements visible as well.

In any case one way to get the "browser size" (the actual size of the
browsers display area) is to examine the size of the current "BODY" tag
(this code, of course, that there IS a body tag available to be examined):

document.getElementsByTagName(''BODY'')[0].clientHeight
document.getElementsByTagName(''BODY'')[0].clientWidth

I''ve only tested this on IE 6.x and FireFox 1.x... it may or may not work on
others.

Of course just because their browser STARTS at that size is no reason to
assume that they''ll leave it that size for the duration of their session.
Your implementation should be able to deal with this behavior - at the very
least the content of the site shouldn''t present assumptions about the
current state of the browser if you''ve only checked that state at the
beginning of the session.

Again, sorry for the lecture. I''m a human factors consultant by trade so
this kind of thing hits home. ;^)

In any case I hope this helps,

Jim Davis


"Jim Davis" <ne********@vboston.com> writes:

document.getElementsByTagName(''BODY'')[0].clientHeight
Why this convoluted way of getting at document.body? I don''t think
there is a browser implementing document.getElementsByTagName and not
document.body (document.body was implemented by IE 3) both are part of
the W3C DOM level 1 HTML standard).

The clientHeight property is not standardized (it was introduced by IE
4), nor is its position on the body element. If one wants to find the
size of the browser''s document viewport, the FAQ has more general ways
of doing it: <URL:http://jibbering.com/faq/#FAQ4_9>
Of course just because their browser STARTS at that size is no reason to
assume that they''ll leave it that size for the duration of their session.



Ah, yes. The devil is in the details, too.
At least, after a page has loaded, the user can see what he is doing by
resizing it.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
''Faith without judgement merely degrades the spirit divine.''


这篇关于Firefox中的Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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