views:

334

answers:

2

I am building an iframe that will go into my clients' web pages. I need to figure out if the user's browser supports javascript and serve back the either the javascript or non-javascript version of the page accordingly.

What's the best way to determine javascript support in this case? I thought about using javascript to rewrite the iframe url to include a GET variable indicating javascript support. However, that would create two requests to the server, one for the initial load and then another once the javascript rewrites the URL. Is there a way to only submit one request? Or is there a better way to determine javascript support?

+5  A: 

Why wouldn't you opt for the <noscript> tag?

<script>
document.write('<iframe src="javascript_enabled_page.html"></iframe>');
</script>

<noscript>
<iframe src="javascript_disabled_page.html"></iframe>;
</noscript>
Hexagon Theory
Clean and simlple
some
Gotta love it. : )
Hexagon Theory
I like it. Don't know why my mind was wrapped around a more complex solution. Thanks!
A: 

Generally speaking, you shouldn't detect JavaScript support. You should serve a page that works without JavaScript, and add JavaScript that alters the page in whatever way is appropriate for when JavaScript is available.

Jim
That is only the case when your service is actually possible without Javascript enabled, though.
Tom