设计一个网站的JavaScript脚本支持和不支持 [英] Designing a website for both javascript script support and not support

查看:153
本文介绍了设计一个网站的JavaScript脚本支持和不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我知道对于您的网站在禁用JavaScript的情况下正常工作很重要。



在我看来,开始思考如何设计这种网站的一种方法是检测主页上的JavaScript,如果它没有启用重定向到另一个版本的网站,不JavaScript代码,并与纯HTML(如Gmail)工作



另一种方法,我有记住例如在网页上的对话框上考虑X(关闭按钮)。如果在没有任何JavaScript干扰的情况下按下X会导致向服务器发送请求,并且在服务器端,我们会在下次渲染页面时隐藏该对话框,而且我们还会将javascript函数绑定到链接的onclick上javascript启用它会立即隐藏对话框。

你怎么看待这个?你将如何设计一个网站来支持这两个方面?

解决方案

处理此问题的一种方法是:




  • 首先,不使用任何javascript创建网站

  • 然后,在每个作品中,在适当位置添加javascript增强功能



通过这种方式,如果JS被禁用,网站的第一版本仍然有效。



你可以用CSS完全一样,自然 - 甚至有一个 CSS裸体日每天都会显示没有CSS的网站的样子^^



一个例子?




  • 您有一个标准的HTML表单,在提交时将数据发布到您的服务器,并且服务器重新创建页面会显示一条消息,如感谢您收藏

  • 然后添加一些JS + Ajax内容:在提交表单时不是重新加载整个页面,而是执行Ajax请求est,只发送数据;作为回报,它显示感谢订阅而不重新加载页面。在这种情况下,如果JavaScript被禁用,第一个标准的做事方式仍然有效。

    这是(部分)所谓的渐进式增强功能


    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脚本支持和不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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