问题描述
好吧,我知道对于您的网站在禁用JavaScript的情况下正常工作很重要。
在我看来,开始思考如何设计这种网站的一种方法是检测主页上的JavaScript,如果它没有启用重定向到另一个版本的网站,不JavaScript代码,并与纯HTML(如Gmail)工作
另一种方法,我有记住例如在网页上的对话框上考虑X(关闭按钮)。如果在没有任何JavaScript干扰的情况下按下X会导致向服务器发送请求,并且在服务器端,我们会在下次渲染页面时隐藏该对话框,而且我们还会将javascript函数绑定到链接的onclick上javascript启用它会立即隐藏对话框。
你怎么看待这个?你将如何设计一个网站来支持这两个方面?
处理此问题的一种方法是:
- 首先,不使用任何javascript创建网站
- 然后,在每个作品中,在适当位置添加javascript增强功能
通过这种方式,如果JS被禁用,网站的第一版本仍然有效。
你可以用CSS完全一样,自然 - 甚至有一个
Okay i know that it's important for your website to work fine with javascript disabled.
In my opinion one way to start thinking about how to design such websites is to detect javascript at the homepage and if it's not enabled redirect to another version of website that does not javascript code and works with pure html (like gmail)
Another method that i have in mind is that for example think of a X (close button) on a dialog box on a webpage. What if pressing the X without any javascript interference lead to sending a request to the server and in the server side we hide that dialog next time we are rendering the page, And also we bind a javascript function to onclick of the link and in case of the javascript enabled it will hide the dialog instantly.
What do you think of this? How would you design a website to support both?
One way to deal with this is to :
- First, create the site, without any javascript
- Then, when every works, add javascript enhancements where suitable
This way, if JS is disabled, the "first" version of the site still works.
You can do exactly the same with CSS, naturally -- there is even one "CSS Naked Day" each day, showing what websites look like without CSS ^^
One example ?
- You have a standard HTML form, that POSTs data to your server when submitted, and the re-creation of the page by the server displays a message like "thanks for subscriving"
- You then add some JS + Ajax stuff : instead of reloading the whole page while submitting the form, you do an Ajax request, that only send the data ; and, in return, it displays "thanks for subscribing" without reloading the page
In this case, if javascript is disabled, the first "standard" way of doing things still works.
This is (part of) what is called Progressive enhancement
这篇关于设计一个网站的JavaScript脚本支持和不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!