0

I'm trying to make a page that shows how to enable JavaScript in various browsers.

The users that view the page will not have JavaScript enabled, so I can't use JavaScript to detect the browser.

How can I detect the browser without using JavaScript, PHP or ASP.NET?

The idea I have in my head is that the page will show the appropriate instructions to enable JavaScript in the user's browsers with pictures and text.

Sorry for the bad english.

Thanks!


EDIT: Is it a bad idea to use conditional comments? Why not?

1
  • Seems like you will have to use the server-side to determine the browser (PHP/ASP/etc, whichever your site runs on). If Javascript is not enabled, you cannot really run anything on the client side. Commented Feb 5, 2012 at 18:18

3 Answers 3

2

You can't. You need something on the back end to read the user agent.

Sign up to request clarification or add additional context in comments.

Comments

2

AFAIK, there's no way, except asking the user:

If you're using Internet Explorer (nice image of the IE logo): click here;

If you're using Firefox (nice image of the Firefox logo): click here;

1 Comment

OK, guess I must do it that way.
1

Your question doesn't leave much room for providing an answer, but I'll give it a shot:

You can use a <noscript> block to provide page content which will only be visible when JavaScript is disabled.

Alternately, you can also use a JavaScript onLoad method to remove an ordinary <div> or similar element from the page when JavaScript is enabled.

The <noscript> element is generally preferred, as it will simply not appear on the page if JavaScript is already enabled.

As far as detecting which browser they're using, you need some technology on the back-end which is capable of parsing the request headers that the browser sends. This can technically be done by the web server itself using server-side include and some clever rewrite rules, but it is actually harder that way than to just learn to use a server-side scripting language.

If you're doing this for a reason (i.e., you're using an embedded webserver with little to no free space), your best option if you only want to provide a static page (in other words, just an HTML file) is to have the page content include a <noscript> block at the top, and an invisible block at the bottom (<div> with hidden), then enable the hidden div on page load via JavaScript.

Include two or three blocks with <a> anchor tags which explain how to enable JavaScript in EACH browser, and have the user click the logo that looks more familiar (all inside your <noscript> block).

That being said, server-side scripting is easy to use, easy to set up, and completely worth learning. It's quite a bit easier and more predictable than doing everything with JavaScript.

2 Comments

> You can use a block to provide page content which will be invisible if javascript is not enabled. Can you clarify?
Apologies, I used the literal < character instead of &lt;, so it hid my <noscript>.. Additionally I meant "visible"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.