显示标签为“web”的博文。显示所有博文
显示标签为“web”的博文。显示所有博文

2009年5月9日星期六

未知选项的表单设计

发现许多的注册表单设计中,性别部分的设计大都这样:使用单选按钮(radio)并默认选中一个(大都为男性,某些女性频道为主的可能为女性)。例如网页申请QQ帐号和注册网易通行证等
网页申请QQ (qq.com)帐号

注册网易(163.com)通行证

雅虎(yahoo.com)的设计比较特立独行,使用选择框(select),并默认不选中任何一个。

而雅虎中国(yahoo.cn)的设计也是使用单选框(radio),但是不选中任何一个。

按常理来说,注册系统并不知道用户的性别是什么,默认选中任何一个都不合理。yummy有一篇文章《中文按1,For English, press 2》提到“如果用户必须做出选择,那就先给他做好一个选择。”,这个道理在某些情况很不错,但是用在这里不合适。

如果不足够了解用户,就不要替用户做选择。

2008年11月7日星期五

文本宽度 及 文本框滚动偏移量(scrollLeft)

背景:
最近将多标签输入框进行修改,把原来随光标(caret)移动的自动建议浮动条改为根据当前标签相对左对齐。
解决方法很简单,计算当前标签前的文本宽度(将需要计算的文本转义后放入一个各字体样式与目标输入框相同的容器,如span中,span.offsetWidth即是文本的宽度。注意:文本框中,中文半角空格的宽度和英文半角空格的宽度显示为不同,虽然这两个空格本质上相同),浮动条根据该值定位即可。

问题:
当标签文本过长,超出文本框宽度时,标签文本会向左滚动,但是此时当前标签前面的文本宽度不变,定位浮动条时需要减去文本向左滚动的尺寸。

网页文档对象中,元素都有一个可读写的scrollLeft属性,表示元素内容相当元素容器向左移动的偏移量。

但是Firefox和Opera有一些例外,如文本框的scrollLeft始终为0,Mozilla的描述是:
If the element can't be scrolled (e.g. it has no overflow), scrollLeft is set to 0.
对于一些不可滚动(scroll,即没有溢出)的元素,scrollLeft始终为0。而单行文本框(在Gecko引擎看来)是不可滚动的,即使将样式指定为overflow:scroll(IE会出现水平和垂直滚动条这样的怪胎)。

虽说单行文本框是不应该出现滚动条这样怪异的形态,但是这不表示它是不可滚动的,当文本宽度大于文本框宽度时,(为了将光标caret显示在文本框可见区域)文本势必向左滚动,如图:

解决办法:
对于文本框不支持scrollLeft的浏览器,一个临时的解决办法是,在文本宽度大于文本框宽度时,浮动条定位在相对文本框后端若干像素(便于输入)的位置,在增量输入时,体验不是太差,但是在光标向前移动使文本向右滚动时,就会出现偏差。

最终解决办法是期待浏览器能够得到正确的scrollLeft值,或者其他巧妙的计算方法。

2008年9月1日星期一

同步Web客户端的时间

富客户端应用的普遍流行,许多操作直接在客户端完成,而一些跟时间相关的操作,客户端时间的正确性就显得尤为重要,一个和标准时间相差得离谱的时间,可能会带来滑稽甚至严重的错误。

在C/S构架下,对时间有要求的应用程序一般解决方法是同步客户端和服务器端的时间,一些要求较高的应用甚至需要专门的时间戳技术。

普通的B/S应用程序一般没有权限同步客户端的时间(也不一定有这个必要),这个问题也有一些解决办法。

1. 响应用户请求时返回服务器时间,并使用计时器(如:window.setInterval)做一个虚拟时钟。但是考虑到浏览器消耗和脚本计时器本身并不精准,长时间运行后时钟会出现较大的误差,予以忽略。

2. 响应用户请求时返回服务器时间,并计算服务器与客户端之间的时间差,每次时间操作均以该差值进行修正(可以专门做一个接口)。或者考虑只有在差值较大的情况下才进行修正(并提醒用户修正客户机时间)。

另外还要考虑用户所在不同时区的情况(Date.getTimezoneOffset)。

但是对于较精准的时间需求,这样仍然有一个问题,即从服务器端响应到客户端返回过程中的网络传输时间。这是一个随机数,根据网络情况和其他偶然因素有关,从几十毫秒到几十秒不等,有时达数分钟之久,最惨的是整个页面超时,当然同步也就没有必要了:)


如上图,客户端从客户机的t0时刻发送请求到服务端,然后服务端在T0时刻得到请求,经过连接数据、计算等操作,最终在T1时刻响应完成,客户端最后在t1时刻加载完成。

此时我们最关心的是服务器返回到客户端加载完成这段时间的网络传输耗时,但是暂时无法精确求得,只有一个相当不凑和方法:客户端发生请求时,带上当时的客户机时间(t0,浏览器请求头信息里一般带有,也可以通过客户端脚本new Date(),此时则需要通过异步请求),服务器计算所耗时间也可以得到,响应时返回服务器计算耗时(T1-T0)以及浏览器请求的时刻(t0)以及服务器时间,客户端加载完成时刻(t1)计算网络传输总共耗时为:(t1-t1)-(T1-T0),之后以一定比例(如1:1)计算响应的网络传输耗时。

结果相当不凑和,而过程又相当麻烦,所以只作为抛砖引玉之篇。



图片来自Baidu图片搜索

2008年8月18日星期一

msn 钓鱼网站

最近频繁出现一个msn钓鱼网站,他本身通过msn传播,例如,你的好友会给你发一个链接(可能会连续发,每次发的地址都不相同,但是链接到同一个地址)。我就接到一些地址:
http://msn.thatzyou.com
http://msn.datsyou.com
http://msn.is-dat-u.com
http://msn.checkpics.com
...

它们都是以msn为子域的二级域名,打开后界面都如下,是一个msn登录窗口(提供msn等IM的web服务很多,所以它至少看起来不是那么假。)。
注:部分地址已经被FF3/Google报告为钓鱼网站。



它一般只有一个页面(即首页),登录窗口下是他的服务条款:
Terms of Use / Privacy Policy:

By filling out this form, you authorize TST Management, Inc to spread the word
about this 100% real and upcomming Messenger Community Site.
You will receive your share of the credit in helping us spread the word. This is a harmless
Community site which is offering users a platform to meet each other for free.

We do not share your private information with any third parties.
By using our service/website you hereby fully authorize TST Management, Inc to send messages
of a commercial nature via Instant Messages and E-Mails on behalf of third parties via the information
you provide us. This is not a "phishing" site that attempts to "trick" you into revealing personal
information. Everything we do with your information is disclosed here. If you are under eighteen (18),
you MUST obtain permission from a parent or guardian before using our website/service.

This page is not affiliated with or operated by Microsoft(tm) or MSN Network(tm).

ANY LIABILITY, INCLUDING WITHOUT LIMITATION ANY LIABILITY FOR DAMAGES CAUSED OR
ALLEGEDLY CAUSED BY ANY FAILURE OF PERFORMANCE, ERROR, OMISSION, INTERRUPTION, DEFECT,
DELAY IN OPERATION OR TRANSMISSION, COMMUNICATIONS LINE FAILURE, SHALL BE STRICTLY LIMITED
TO THE AMOUNT PAID BY OR ON BEHALF OF THE SUBSCRIBER TO THIS SERVICE.

We may temporarily access your MSN account to do a combination
of the following:
1. Send Instant Messages to your friends promoting this site.
2. Introduce new entertaining sites to your friends via Instant Messages.


This is a free service. You will not be asked to pay at any time.
You will not be subscribed to anything asking for payment.
This service is made possible by many hours of human effort.

TST Management, Inc reserves the right to change the terms of use / privacy policy
at any time without notice. To view the latest version of this privacy policy,
simply bookmark this page for future reference.

You understand that this agreement shall prevail if there is any conflict between this
agreement and the terms of use you accepted when you signed up with MSN. You also
understand that by temporarily accessing your msn account, TST Management, Inc
is NOT agreeing to MSN's terms of use and therefore not bound by them.

This agreement shall be construed and governed by the law of the
republic of Panama. You expressly consent to the exclusive venue
and personal jurisdiction of the courts located in the Republic of
panama for any actions arising from or relating to this agreement.

If any provision of this agreement is held to be invalid, illegal or unenforceable
for any reason, such invalidity, illegality or unenforceability shall not effect any
other provisions of this agreement, and this agreement shall be construed as if
such invalid, illegal or unenforceable provision had not been contained herein.


Copyright 2008 TST Management, Inc