Re: Detecting Javascript enabled (browser side)
Re: Detecting Javascript enabled (browser side)
- Subject: Re: Detecting Javascript enabled (browser side)
- From: John Huss <email@hidden>
- Date: Mon, 10 Aug 2009 13:22:05 -0500
To detect if _javascript_ is enabled, I do it when the user logs in.
So in the login page I have:
<input type="hidden" id="jsEnabled" name="jsEnabled" value=""/>
<input type="submit" class="button" value="Log In" >
This is inside a WOForm. The form submits to a direct action that logs the user in and has this code:
session().isJSEnabled = "true".equals( request().stringFormValueForKey("jsEnabled") );
The session has this field declared:
public boolean isJSEnabled = false;
John
On Mon, Aug 10, 2009 at 12:39 PM, Mark Gowdy
<email@hidden> wrote:
Hello,
We recently started using the Wonder Ajax framework (which is amazing btw, well done guys), but we want to be able to detect if _javascript_ is enabled on the client's browser.
I suspect this is a problem solved by many before, but I cannot seem to find a reliable solution.
I have considered setting cookies using client-side _javascript_, then checking for them server-side.
But conditions can arise where this might not work.
Checking client-side should be the simplest and more reliable way, but I have hit a little problem.
The <noscript> condition is simple (no issues there)
The <script> condition is less simple. You have to use a document.write('..');
The problem is now an escaping issue (as demonstrated below):
TheComponent.html
---------------------------
<noscript>
<webobject name = ClickedRemoveFromOrder> Remove </webobject>
</noscript>
<script type="text/_javascript_">
document.write('<wo:AjaxUpdateLink action = "" title = "Remove from basket" class = "remove" updateContainerID = "$mediaItem.pk.toString"> Remove </wo:AjaxUpdateLink>');
</script>
---------------------------
Generates:
---------------------------
<noscript>
<a class="remove" title="Remove from basket" href="" Remove </a>
</noscript>
<script type="text/_javascript_">
document.write('<a href="" {}, '3.0.17.10.0.0.1.3.11.1.1.1.1.3.1.5.1.3.3');" title="Remove from basket" class="remove"> Remove </a>');
</script>
---------------------------
I believe I need to escape the following characters so that they can be inserted into the document.write as a parameter.
' /
and probably a few more?
Is there a container I can use that will escape the generated HTML automatically?
Or maybe an additional binding on AjaxUpdateLink (escapeForJavascript)?
Other suggestions welcome.
Thanks in advance,
Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden