Hi Guys
I am working on a project where I needed to detect whether javascript was enabled and react accordingly, drawing different items on the page.
having looked through google results I came accross a few examples, but none of them instantly applicable to silverstripe. Eventually I did manage to port one of the php form solutions in so that you can simple call <% if Javascript %> in the template.
The only downside to this that I can see is that when javascript is enabled and you refresh the page you get a 'Resend request' from the browser to resend the hidden form. Mayb somone knows a way around this?
Anway here is the code:
mysite/code/Page.php
class Page_Controller extends ContentController {
.
.
.
function Javascript(){
if (isset($_POST['jstest'])) {
return true;
}
else {
return false;
}
}
}
mysite/templates/Page.ss
.
.
.
<body>
<% if Javascript == 0 %>
<form name="jsform" id="jsform" method="post" style="display:none">
<input name="jstest" type="text" value="true" >
<script language="javascript">
document.jsform.submit();
</script>
</form>
<% end_if %>
.
.
.
mysite/templates/Layout/Page.ss
.
.
.
<% if Javascript %>
.....Do some fancy java stuff
<% else %>
do some boring stuff
<% end_if %>
.
.
.