Gossamer Forum
Home : General : Internet Technologies :

Seeking Javascript detector - if javascript, stay, if not, redirect

Quote Reply
Seeking Javascript detector - if javascript, stay, if not, redirect
Hi All

I know I've seen something that can detect if javascript is enabled in a browser.

If the browser supports javascript, then visitor stays on page and uses form

If browser does not support javascript, then visitor is redirected or gets some message saying, "sorry, your browser doesn't have javascript enabled", etc...

I can't locate it for the life of me. I know that this should have been easy to find.

Would anyone know of such a script?

Many thanks :)

------------------------------------------
Quote Reply
Re: [DogTags] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
See if this works....

http://javascript.internet.com/...nabled-redirect.html

<snip>If your visitor has JavaScript enabled in their browser, they are automatically redirected to your JavaScript-enhanced page. If their browser doesn't support JavaScript or they have it disabled, the NOSCRIPT code will display a link to another page without JavaScript. </snip>
Quote Reply
Re: [Watts] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Thanks, Watts Smile

Yeah, I was looking at that one earlier.

I want to do the opposite.

What I want to do is redirect only if the user does not have javascript.

If they do have javascript enabled, then they would stay on the page. Like:

If javascript > display HTML

If no javascript > display instructions how to enable javascript

Go Eagles! Smile

------------------------------------------

Last edited by:

DogTags: Feb 1, 2005, 11:10 PM
Quote Reply
Re: [DogTags] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
How about META-REFRESH redirect inside <noscript>...</noscript> tags.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Thanks, dan Smile

Do you think the following would work?

Code:
<html>
<head>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">

html, forms, other javascripts go in here....

</script>

<noscript>

Meta Refresh or some instructions go here....

</noscript>
</body></html>

------------------------------------------
Quote Reply
Re: [DogTags] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Should, but I don't think you need to the <javascript>...</javascript> block - just the regular code (HTML, DHTML, JS, etc.) that JS-compatible browsers will see (others will be redirected to the META-REFRESH url).

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Here's what I tried:

Code:
<html>
<head>

<noscript>
If you see this message, your browser is not running JavaScript.
</noscript>

</head>
<body>
Fred - Main page contents here.
</body>
</html>

If js was enabled, browser displayed "Fred - Main page contents here."

If js was not enabled, browser displayed both messages - "If you see this message, your browser is not running JavaScript.Fred - Main page contents here."

In other words, if js was not enabled, the main page content still displayed.

------------------------------------------
Quote Reply
Re: [DogTags] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
What you can do is to change <noscript>...</noscript> to:

<noscript>
<meta http-equiv="refresh" content="0;URL=http://www.yourdomain.com/nojavascript.html">
</noscript>

...where nojavascript.html explains that they need to enable JS, with instructions on how to.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Technically, you're not allowed to put noscript tags inside the head section...

Adrian
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
What about inserting remote contents if js is enabled - but displaying the < noscript > content if js not enabled ?

Hmmm....kind of like a javascript version of an ssi call

Might something like the following be possible?

Code:
<html>
<head>
<head>
<body>
<script language="javascript">
<!--
function insert_the_following_remote_html("http://www.domain.com/page_content.html"){
}
// -->
</script>
<noscript>
Oops! You gotta enable javascript, dude!
</noscript>
</body>
</html>

------------------------------------------

Last edited by:

DogTags: Feb 2, 2005, 12:41 AM
Quote Reply
Re: [DogTags] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Maybe it could be this easy:

Code:
<html>
<head>
<head>
<body>
<script language="JavaScript" src="http://domain.com/file.js"></script>
<noscript>
Oops! You gotta enable javascript, dude!
</noscript>
</body>
</html>

Just make the file.js have all the html and stuff.

------------------------------------------
Quote Reply
Re: [brewt] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
In Reply To:
Technically, you're not allowed to put noscript tags inside the head section...

Thanks, Adrian Smile

I had seen it both ways.

------------------------------------------
Quote Reply
Re: [brewt] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
The <noscript>..</noscript> is outside the head section - with the meta-refresh also outside the head section, which works for MSIE and NS.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [DogTags] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Yep, that should work. What you can do is to test the codes examples you have provided in your HTML editor.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Many thanks, Dan Smile

------------------------------------------

Last edited by:

DogTags: Feb 2, 2005, 1:24 AM
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Well, technically, the meta tag can't go outside of the head :P

Adrian
Quote Reply
Re: [brewt] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
I agree. Usually I do place in head section, but there has been times when I have found it necessary - e.g., third party scripts using partial templates (editable only outside head section), where I do not want to edit actual scripts so as to make upgrades easier. But it works, at least for MSIE and newer versions of NS - which tend to be more tolerant of 'sloppy' HTML.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Hi,
Sorry to jump in but I have a question about the <noscript> </noscript> tags.
Are there limitations on which browsers understand these tags?
I'm building a site that uses javascript but I also want to include alternative content for those users that can't/don't use javascript. I want my site to look good with or without the javascript.
Thanks.
Quote Reply
Re: [jai] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
The <noscript> tag has been compatible with MSIE since the beginning, and with Netscape since version 3. I would imagine that all Mozilla (and Gecko-based) browsers including Firefox/Firebird as well. As far as other browsers (which should only account for a few percent of your traffic at best), you would have to check their websites.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] Seeking Javascript detector - if javascript, stay, if not, redirect In reply to
Thanks Dan.
So it pretty well covers 98% of browsers out there and as for the other 2%, well .... it's about time they upgraded. I can't understand why anyone would still be using those old browsers.
Simon.