Anish Gupta
Anish Gupta

Reputation: 2226

How to detect the browser without JavaScript, PHP or ASP.NET?

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?

Upvotes: 0

Views: 944

Answers (3)

Tom B
Tom B

Reputation: 539

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.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 692231

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;

Upvotes: 2

thenetimp
thenetimp

Reputation: 9830

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

Upvotes: 2

Related Questions