简体   繁体   English

服务器端逐步增强?

[英]progressive enhancement on the server side?

Currently many of the links on our pages get changed to href="javascript:void(0);" 目前,我们页面上的许多链接已更改为href="javascript:void(0);" on pageload, but if you're impatient (as most users are) you can click the links before the page loads and land on the clunkier, non-javascript, non-ajax pages. 关于页面加载,但如果您不耐烦(大多数用户都如此),则可以在页面加载之前单击链接,然后进入较笨拙的,非JavaScript,非ajax页面。

I'm thinking about progressive enhancement a lot these days, and I predict the majority of our users will have javascript enabled (no data yet, we havn't yet launched alpha) 这些天,我一直在考虑逐步增强功能,我预计我们的大多数用户都将启用javascript(尚无数据,我们尚未启动alpha)

Is it a bad idea to generate some indicator that a user has javascript enabled for the session, and then serve pages that assume javascript? 生成一些指示符,指示用户已为会话启用了javascript,然后提供使用javascript的页面,这是一个坏主意吗? (ie. have the server put href="javascript:void(0);" from the start) (即href="javascript:void(0);"从一开始href="javascript:void(0);"服务器放置href="javascript:void(0);"

Why not just do this? 为什么不这样做呢?

<a href="oldversion.htm" onclick="...something useful......; return false;">link</a>

return false tells the browser not to carry on to the url in the href. return false告诉浏览器不要继续使用href中的url。

Now js visitors get fancy js, and non-js users fall back silently; 现在,js访问者可以使用精美的js,非js用户则默默回退; and there is no need for changing links on pageload. 并且无需更改页面加载上的链接。

Do you do your progressive enhancement on load? 您是否在逐步提高负载? You could try to move it to (a cross-browser version of) DOMReady. 您可以尝试将其移至DOMReady(的跨浏览器版本)。

Couldn't you delegate this to the document, to keep your HTML clean? 您不能将其委托给文档以保持HTML干净吗?

For example, in jQuery: 例如,在jQuery中:

$( document )
    .click( function(){ return false })
    .ready( function(){ $( this ).unbind( "click" ) } )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM