user38339
user38339

Reputation: 365

Determine whether browser supports javascript from within iFrame?

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?

Upvotes: 2

Views: 533

Answers (2)

Jim
Jim

Reputation: 73936

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.

Upvotes: 0

Hexagon Theory
Hexagon Theory

Reputation: 44803

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>

Upvotes: 5

Related Questions