开发者

Which PHP-template to load depends on javascript support

I have the following scenario:

A multiple step registration procedure. Let's say it's 4 steps, and each step depends on previous input. This could be solved with or without Javascript.

Without JS: A "proceed"-button is attached to each step With JS: The next part is automatically revealed to the user when previous step is开发者_JAVA技巧 done. (No "proceed"-button exists.

The problem is: How do my template engine know which one to present? With or without proceed buttons? You can not just try to test a JS-block of code to determine if it is enabled before PHP loads the template.

One way I've worked out is the possibility that the initial load of the visit sends an ajax-request to a file on the server which only purpose is to set $_SESSION['JS_ENABLED'] = 1 or something like that.

I don't like this. The HTTP request for that file might very well fail leaving the site in belief that the visitor has JS disabled.

I think I need a new approach. Please enlighten me =)


You could do somethin like this:

<p>Step ....</p>
<a id="proceed_link" href="no_script_proceed_link.php">Proceed</a>
<script type="text/javascript">
// example with jquery
$.getScript('script/url.js',function(){ 
   $('#proceed_link').hide();
   // other stuff when scripts are available
});
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜