Detecting Javascript availability...

D

Dag Sunde

We have this web-app that requires Javascript to
be enabled in the UA (this is okay'ed by our customer).

Now I want to make a "pre" page before the login screen,
informing the user that he/she must have JS turned on.

Problem is that I would prefer to show this page only if
JS isn't on. (and hence, I have a "Chicken/Egg" problem).

If neccessary, we can require IE-only as UA.

Any pointers, suggestions or comments on thisone?

TIA...
 
B

BootNic

Dag Sunde said:
We have this web-app that requires Javascript to
be enabled in the UA (this is okay'ed by our customer).

Now I want to make a "pre" page before the login screen,
informing the user that he/she must have JS turned on.

Problem is that I would prefer to show this page only if
JS isn't on. (and hence, I have a "Chicken/Egg" problem).

If neccessary, we can require IE-only as UA.

Any pointers, suggestions or comments on thisone?

TIA...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Check JavaScript
</title>
</head>
<body>
<script type="text/javascript">
function proceed(){
document.location.href = 'http://www.download.com'
}
onload = proceed
</script>
<noscript>
<h1 style="color:red;text-align:center;">
JavaScript must be enabled
</h1>
<p>
perhaps some direction on how to enable javascript
</p>
</noscript>
</body>
 
D

Dag Sunde

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Check JavaScript
</title>
</head>
<body>
<script type="text/javascript">
function proceed(){
document.location.href = 'http://www.download.com'
}
onload = proceed
</script>
<noscript>
<h1 style="color:red;text-align:center;">
JavaScript must be enabled
</h1>
<p>
perhaps some direction on how to enable javascript
</p>
</noscript>
</body>

Thanks a lot!

I now realize that the <noscript> tag is supported all the way
to xhtml strict, and all is well.
 
R

Randy Webb

Dag said:
Thanks a lot!

I now realize that the <noscript> tag is supported all the way
to xhtml strict, and all is well.

Not as well as you think, and its material to your question.

Leave the noscript section in the page itself. If script is not
available (whether not in the UA or disabled) then the page won't be
redirected and the user will see it. Then, it doesn't matter whether
noscript is supported or not.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 
D

Danny@Kendal

Dag Sunde said:
We have this web-app that requires Javascript to
be enabled in the UA (this is okay'ed by our customer).

Now I want to make a "pre" page before the login screen,
informing the user that he/she must have JS turned on.

Problem is that I would prefer to show this page only if
JS isn't on. (and hence, I have a "Chicken/Egg" problem).

Place the login section in a hidden <div> and then make another unhidden
<div> which has some suitable message about javascript.

Once the page loads, hide the message and unhide the login section.
 
V

VK

Using the Occam's raisor (also called KISS in California) :

(It works for all browsers starting with Netscape 2.0 and including
Lynx)

<html>
<head>
<title>Welcome to my company!</title>
<noscript>
<meta http-equiv="Refresh"
content="1;URL=http://www.myserver.com/noscript.html">
</noscript>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF">
<p>Login page</p>
</body>
</html>
 
D

Dag Sunde

Randy Webb said:
Dag Sunde wrote:

Not as well as you think, and its material to your question.

Leave the noscript section in the page itself. If script is not
available (whether not in the UA or disabled) then the page won't be
redirected and the user will see it. Then, it doesn't matter whether
noscript is supported or not.

I did it like below, can you see any problems with that?

<?xml version='1.0' encoding='iso-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RegWeb - Sjekker JavaScript</title>
<link type="text/css" rel="stylesheet" href="styles/ekstranett.css" />
<script type="text/javascript">
function fwdOnScriptPresent() {
document.location.href = './pages/UASettings.asp';
}
</script>
</head>

<body onload="fwdOnScriptPresent();">
<noscript>
<h2 style="color:red;">
JavaScript must be supported, or turned on...
</h2>
<h3>How to proceed:</h3>
<p>yada, yada...</p>
</noscript>
</body>
</html>
 
R

Randy Webb

Dag said:
I did it like below, can you see any problems with that?

<?xml version='1.0' encoding='iso-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RegWeb - Sjekker JavaScript</title>
<link type="text/css" rel="stylesheet" href="styles/ekstranett.css" />
<script type="text/javascript">
function fwdOnScriptPresent() {
document.location.href = './pages/UASettings.asp';
}
</script>
</head>

<body onload="fwdOnScriptPresent();">
<noscript>

Remove the noscript tag.
<h2 style="color:red;">
JavaScript must be supported, or turned on...
</h2>
<h3>How to proceed:</h3>
<p>yada, yada...</p>
</noscript>

Remove the closing noscript tag.
</body>
</html>

Consider this scenario:

The UA doesn't support redirection via script. Whether it doesn't
support .href or the location object. The script will fail, yet the user
won't see the noscript section. Leaving it out leaves it readable by
anyone, for whatever reason, that doesn't get redirected.

There is an ongoing thread at the moment entitled "Problems with JS
turned off" that discusses this very point.
 
R

Randy Webb

VK said:
Using the Occam's raisor (also called KISS in California) :

(It works for all browsers starting with Netscape 2.0 and including
Lynx)

Are you positive about that? I'm not.
<html>
<head>
<title>Welcome to my company!</title>
<noscript>
<meta http-equiv="Refresh"
content="1;URL=http://www.myserver.com/noscript.html">

IE6 explicitly allows the disabling of META Refresh. If the browser is
Meta disabled and script disabled your user will be staring at a blank
screen (test it).

Also, the noscript element is not allowed in the head section anyway.
And what a browser does with invalid HTML is a guess at best.
 
T

Thomas 'PointedEars' Lahn

Dag said:
I did it like below, can you see any problems with that?

Alas, I can see plenty of them.
<?xml version='1.0' encoding='iso-8859-1' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Whatever M$ tells you, Internet Explorer (IE) does not support XHTML. I
do hope that you don't serve this XHTML as text/html to workaround that,
but as application/xhtml+xml and serve an HTML alternative as text/html
to IE and other non-XHTML UAs.

<http://www.hixie.ch/advocacy/xhtml>

Although it is Valid markup, there is no point whatsoever in declaring XHTML
1.0 Transitional. Like the man said, you can't eat the cake and have it.
Either you want clean markup (e.g. to speed up the parsing process) or you
don't want it. If the former, declare HTML 4.01 Strict, XHTML 1.0 Strict
or even XHTML 1.1 Strict if you have to; if the latter, declare HTML 4.01
Transitional.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>

The character declaration meta element is redundant in valid XHTML served
with the appropriate Content Type. An XML parser has to determine the
encoding of a document before building the parse tree; a character
declaration of this kind simply is too late at this line.
[...]
<link type="text/css" rel="stylesheet" href="styles/ekstranett.css" />

This alone is not supposed to work in correctly served XHTML. XHTML
documents are the result of an application of XML and so an XML processing
instruction (PI) before the root element (here: HTML) is required to
specify the used stylesheet. This means you either specify the CSS
resource in the PI, or provide a `style' element with an `id' attribute
value while referring to the fragment identifier in the PI. The former
is recommended to avoid declaring style content as CDATA or to escape
markup characters (e.g. `>', both CSS child selector and XML TAGC
delimiter).

<script type="text/javascript">
function fwdOnScriptPresent() {
document.location.href = './pages/UASettings.asp';
}
[...]
<body onload="fwdOnScriptPresent();">

The function is redundant so far (and therefore a little bit inefficient
compared to the alternative): the one line could have been easily included
in the event handler attribute value.

`document.location' is deprecated long since. Use `window.location' or
`location' if you can be sure that in the targeted UAs the `window' property
would refer to the Global Object (you can save one lookup this way and your
code becomes shorter).

No syntax errors here, but you should be aware that if you include e.g.
certain comparison operators to the script without either declaring script
content as CDATA (character data) or escaping those operators you will run
into trouble; the default content type of the `script' element is PCDATA
(parsed CDATA): e.g. an undeclared `<' is considered an STAGO delimiter.
That's why it is recommended to include script files (containing unescaped
code without CDATA declarations, of course) instead.

<noscript>

There is no point in using the `noscript' element in this document, unless
the above code is just an example and you want a timed redirection. If not,
just let the script code execute within the `head' element and a JS capable
UA will never reach this line.
<h2 style="color:red;">

JavaScript must be supported, or turned on...

The assumption "as is" is wrong and based on a misconception. Although
non-compliant regarding the HTML 4.01 Specification, many user agents tend
to ignore the value of the `type' attribute of the `script' element and
use the default scripting language always. If, for some strange reason,
the default scripting language of a UA would be not JS, JS could be
supported and this section be displayed anyway. I have yet to see such
an UA, though.
</h2>
<h3>How to proceed:</h3>

[...]
</noscript>
[...]


HTH

PointedEars
 
T

Thomas 'PointedEars' Lahn

VK said:
Using the Occam's raisor (also called KISS in California) :

I'm afraid it's more stupid than simple.
(It works for all browsers starting with Netscape 2.0 and including
Lynx)

[gibberish code]

Certainly not. It is far from being Valid HTML, let alone a usable
document.


PointedEars
 
D

Dag Sunde

Thomas 'PointedEars' Lahn said:
Dag said:
"Randy Webb" <[email protected]> wrote [...]:

<snipped />

Thank you for a long list of explanations to the different issues,
both of you...

some of it was sloppyness in my example, some of it was completely new
to me, and some it is hard to believe.

I'll try to absorb it during the next week (I'm on vacation :)).

Tank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top