开发者

Why Unobtrusive JavaScript?

Just been reading on Wikipedia

  • Separation of functionality (the "behavior layer") from a Web page's structure/content and presentation[1]
  • Best practices to avoid the problems of traditional JavaScript programming (such as browser inconsistencies and lack of scalability)
  • Progressive enhancement to support user agents that may not support advanced JavaScript functionality[2]

In these days where Javascript libraries like jQuery rule the internet, why still take care of this Unobtrusiveness?

Point 2 and 3 about browser's not supporting Javascript and inconsistency?

Which browsers? If they are not in the IE 6.0+, FF 2+, Safari 3.0+, Opera 9.0+, Ch开发者_Python百科rome range, frankly I don't care! (I might care about Mobile though..)

Ok a user can disable Javascript, but do I have to make sure everything is 'Unobtrusive' just for that? I am asking this because I have by sumbit buttons (links actually because styling HTML buttons is a pain) triggered with Javascript. Is this a bad idea?


Just ask yourself the question: do I want to cater to casual computer users who don't have Javascript enabled (many Windows XP installations esp enterprisy ones have Javascript disabled by default on IE for non-trusted zone). Is it OK to lose a small percentage of userbase who use such restricted browser settings? If the answer to both is yes, you might not really want to bother about "unobtrusive Javascript".

I think the least you can do is show them a warning DIV at the top of the page (e.g. like the one used by Stackoverflow) that your site requires Javascript and won't function properly without it; seems like a good compromise if you can't go the unobtrusive way.


If self-employed, you're in luck: giving up on a percentage of your potential user base to spend more time building better things for the others is your call.

Your employer may have other requirements in mind, some of which may be mandatory legal requirements such as making a web site available to disabled people who read the pages through a text-only braille interface with no JavaScript support, and others which are elementary economic requirements such as making the site available to no-javascript search engine crawlers.

It is in your best interest to check for such requirements first, lest you have to rewrite most of your presentation layer to take it into account later.


Consider what would happen if a user doesn't have javascript enabled, will your site still work with links rather than submit buttons. It's quite rare but some users do disable javascript by default.

You should progressively enhance your html using javascript to accommodate users with or without javascript.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜