473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Javascript error message using <meta> tags

Hi everyone,

We' ve come to the conclusion that we wish the user to be directed to
an error page if javascript is disabled <enter comment about how a
webpage shouldn't rely on javascript here :) >. I've read quite a few
posts on how to do this, but none meet my need (the two main
suggestions was set a jsEnabled variable in a <scriptsection of the
HTML and read it in PHP, and the other suggestion was by default
loading the non js page, and use js to redirect to the js page - I
didn't like either of them).

The behavoiur I desire is this: if(javascriptEnabled){print out
page;}else{redirect to you need to enable javascript page;}

I came up with the idea of using a meta tag in a <noscriptsection,
and was hoping to get suggestions from this newsgroup. What I'm
suggesting is essentially:

<html>
<noscript>
<meta http-equiv="refresh" content="2;url=http://webdesign.about.com">
</noscript>

QST - do you have to put the absolute URL in, and can the time be zero?

The W3C says that: "Note. Some user agents support the use of META to
refresh the current page after a specified number of seconds, with the
option of replacing it by a different URI. Authors should not use this
technique to forward users to different pages, as this makes the page
inaccessible to some users. Instead, automatic page forwarding should
be done using server-side redirects." Is this because only *some* user
agents can forward the page?

Nov 1 '06 #1
8 2825
Taras_96 said the following on 11/1/2006 12:29 AM:
Hi everyone,

We've come to the conclusion that we wish the user to be directed to
an error page if javascript is disabled <enter comment about how a
webpage shouldn't rely on javascript here :) >.
Your logic is backwards. Don't redirect on JS Disabled, redirect on JS
Enabled.
I've read quite a few posts on how to do this, but none meet my need
(the two main suggestions was set a jsEnabled variable in a <script>
section of the HTML and read it in PHP,
That requires a round trip to the server.
and the other suggestion was by default loading the non js page, and
use js to redirect to the js page - I didn't like either of them).
The *best* solution is to create a site that works without JS and then
enhance it using JS. Then, it doesn't matter.
The behavoiur I desire is this: if(javascriptEnabled){print out
page;}else{redirect to you need to enable javascript page;}
Again, your logic is backwards.
if(javascriptEnabled){redirect}else{print out error page}

Just for you though, redirecting me to a page that says "You need to
enable Javascript" would make you look pretty intelligent to users of
UA's that don't even support JS. How do you enable something the UA
doesn't support?
I came up with the idea of using a meta tag in a <noscriptsection,
and was hoping to get suggestions from this newsgroup. What I'm
suggesting is essentially:
It's a dumb idea.
<html>
<noscript>
<meta http-equiv="refresh" content="2;url=http://webdesign.about.com">
</noscript>

QST - do you have to put the absolute URL in, and can the time be zero?
Did you test it? I bet you didn't or you wouldn't have to ask.
The W3C says that: "Note. Some user agents support the use of META to
refresh the current page after a specified number of seconds, with the
option of replacing it by a different URI. Authors should not use this
technique to forward users to different pages, as this makes the page
inaccessible to some users. Instead, automatic page forwarding should
be done using server-side redirects." Is this because only *some* user
agents can forward the page?
IE6 and IE7 users can explicitly disable META Redirects.

So, what do users with Script and META disabled get???

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 1 '06 #2
Taras_96 wrote:
Hi everyone,

We' ve come to the conclusion that we wish the user to be directed to
an error page if javascript is disabled <enter comment about how a
webpage shouldn't rely on javascript here :) >. I've read quite a few
posts on how to do this, but none meet my need (the two main
suggestions was set a jsEnabled variable in a <scriptsection of the
HTML and read it in PHP, and the other suggestion was by default
loading the non js page, and use js to redirect to the js page - I
didn't like either of them).
Redirect users if script is enabled.

The behavoiur I desire is this: if(javascriptEnabled){print out
page;}else{redirect to you need to enable javascript page;}
Have the error page in the main page with the script-dependent content.
Wrap each in a div and use CSS to display the error message and hide
the script-dependent content.

Use a script element immediately after the style element that
establishes the above to load a style sheet that reverses the display
properties:

<html>
<head>
<style ...>
#mainContent {display: none};
#noscriptMsg {display: block};
</style>
<script ...>
/* script to load style sheet to reverse above styles:
#mainContent {display: block};
#noscriptMsg {display: none};
*/
</script>
...

I came up with the idea of using a meta tag in a <noscriptsection,
and was hoping to get suggestions from this newsgroup. What I'm
suggesting is essentially:

<html>
<noscript>
<meta http-equiv="refresh" content="2;url=http://webdesign.about.com">
</noscript>
To be valid HTML, noscript elements must be in the body and contain at
least one block element, meta elements must be in the head.

What any particular browser makes of the above is the result of error
correction and likely not consistent in different ones.
--
Rob

Nov 1 '06 #3
>
Your logic is backwards. Don't redirect on JS Disabled, redirect on JS
Enabled.
>
The *best* solution is to create a site that works without JS and then
enhance it using JS. Then, it doesn't matter.
The behavoiur I desire is this: if(javascriptEnabled){print out
page;}else{redirect to you need to enable javascript page;}

Again, your logic is backwards.
if(javascriptEnabled){redirect}else{print out error page}
I think the contrary. IMO, when I'm coding, I tend to react on errors,
rather than reacting on the lack of errors. The code above reacts on
the lack of errors - your logic is reacting (redirecting in this case)
based on the absence of an error (in this case the error being
javascript disabled).

Furthermore, I don't like your solution because it penalises users that
are doing the right thing - enabling javascript (well, its the right
thing in my context anyway). Those that have javascript enabled have to
send an extra request each time they want to view a new page.

Secondly, I would need to rewrite all of the links throughout the site
to go to this error page, and then make the error page repost all of
the form variables. This isn't impossible, but I was hoping for an
easier, cleaner solution.
Just for you though, redirecting me to a page that says "You need to
enable Javascript" would make you look pretty intelligent to users of
UA's that don't even support JS. How do you enable something the UA
doesn't support?
.....
>
So, what do users with Script and META disabled get???
Maybe I should have been a bit clearer. The website is targeted at a
group that is generally computer illiterate, meaning that probably 90%
of the users will be running IE on Windows. The other 10% will almost
definitely have some UA that does support javascript. If not, well,
you're going to have to install another browser. IMO, saying to your
users that 'you must enable javascript', although not ideal, is not the
end of the world. The website's functionality is a product, and like
lots of software products, there are prerequisites to running this
product. We see similar situations everyday - 'this software requires
Windows', 'this software requires Linux', etc.

Having the META disabled is a problem, and was the type of information
I was looking for.
I came up with the idea of using a meta tag in a <noscriptsection,
and was hoping to get suggestions from this newsgroup. What I'm
suggesting is essentially:

It's a dumb idea.
Why? Constructive criticism would be nice. I think it would be a good
idea if you couldn't disable META.
<html>
<noscript>
<meta http-equiv="refresh" content="2;url=http://webdesign.about.com">
</noscript>

QST - do you have to put the absolute URL in, and can the time be zero?

Did you test it? I bet you didn't or you wouldn't have to ask.
I was more after what the standards say about the above attributes, and
what browser support is there for those standards and if the browsers
divert from the standards, how do they divert? I could test it in the
browsers I have, but I wanted to know how the browsers out there react.
>
IE6 and IE7 users can explicitly disable META Redirects.
Ahhh, some constructive criticism..

Taras

Nov 1 '06 #4
HI
Have the error page in the main page with the script-dependent content.
Wrap each in a div and use CSS to display the error message and hide
the script-dependent content.

Use a script element immediately after the style element that
establishes the above to load a style sheet that reverses the display
properties:

<html>
<head>
<style ...>
#mainContent {display: none};
#noscriptMsg {display: block};
</style>
<script ...>
/* script to load style sheet to reverse above styles:
#mainContent {display: block};
#noscriptMsg {display: none};
*/
</script>
...
That's a really good idea - thanks. I think I will place the error
message in a noscript element, so if JS is enabled then the user won't
be given an error message while he waits for the page to load (which
would be confusing).
To be valid HTML, noscript elements must be in the body and contain at
least one block element, meta elements must be in the head.
What any particular browser makes of the above is the result of error
correction and likely not consistent in different ones.
Thanks again, I'll give it a shot

Nov 1 '06 #5
VK
Taras_96 wrote:
We' ve come to the conclusion that we wish the user to be directed to
an error page if javascript is disabled <enter comment about how a
webpage shouldn't rely on javascript here :) >. I've read quite a few
posts on how to do this, but none meet my need (the two main
suggestions was set a jsEnabled variable in a <scriptsection of the
HTML and read it in PHP, and the other suggestion was by default
loading the non js page, and use js to redirect to the js page - I
didn't like either of them).
You must be was reading wrong posts then ;-) Otherwise you would use
the default tool provided in HTML for such situations: NOSCRIPT tag. At
least this is what I'm using all the time.

<html>
<head>
<title>Lorem ipsum</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
color: #000000;
background: #FFFFFF;
}
noscript {
position: absolute;
top: 20px;
left: 20px;
width: 40%;
margin: 0px 0px;
padding: 1em 1em;
border: medium solid red;
font: 100% Verdana, Geneva, sans-serif;
background-color: white;
}
</style>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut congue
eros sit
amet pede. Nam id mauris quis diam adipiscing adipiscing.
Pellentesque id est
sed dolor elementum nonummy. Suspendisse elementum varius leo.
Vivamus consequat,
augue non consectetuer eleifend, enim magna aliquet justo, rhoncus
lacinia lorem
justo sed nulla. Mauris at nunc et magna vestibulum ornare. Mauris
eget nisi.
Sed erat turpis, nonummy ut, suscipit sagittis, iaculis sit amet,
elit. Phasellus
aliquet mollis lorem. Nam turpis. Vivamus sollicitudin tristique
lorem. Praesent
sit amet nibh id dolor venenatis accumsan. Phasellus tincidunt.
Nullam porta,
nisl eget congue nonummy, ligula nisi porta tortor, sit amet rhoncus
diam sapien
nec quam. Proin dignissim quam sit amet sem. Aenean egestas, lectus
sed mollis
rhoncus, lorem tellus aliquam lacus, eget congue velit velit sed
tellus. Etiam
nulla libero, feugiat vitae, scelerisque a, semper sed, ligula.</p>
<noscript>
<h4 style="color:red">Client-side scripting was disabled.</h4>
<p>Some (or all) extended features of this page will not be
available.</p>
<p><a href="ConceptualistHell.html">Dismiss this warning</a></p>
</noscript>
</body>
</html>

By using conditional comments you even can redirect users with
intentionally broken IE to one page, and all other intentionally broken
UA's to another page:

<noscript>
<h4 style="color:red">Client-side scripting was disabled.</h4>
<p>Some (or all) extended features of this page will not be
available.</p>
<!--[if IE]>
<p><a href="IEConceptualistHell.html">Dismiss this warning</a></p>
<![endif]-->
<![if !IE]>
<p><a href="nonIEConceptualistHell.html">Dismiss this warning</a></p>
<![endif]>
</noscript>

Nov 1 '06 #6
Taras_96 said the following on 11/1/2006 5:33 AM:
>Again, your logic is backwards.
if(javascriptEnabled){redirect}else{print out error page}

I think the contrary. IMO, when I'm coding, I tend to react on errors,
rather than reacting on the lack of errors.
The error isn't JS enabled or disabled. The error is depending on JS and
when you depend on it, you have to react to that error. And the most
reliable way (the only way) to know if script is enabled is for script
to tell you.
The code above reacts on the lack of errors - your logic is reacting
(redirecting in this case) based on the absence of an error (in this
case the error being javascript disabled).
No, it reacts to a confirmation of the features I want. In your case,
the feature you want is JS enabled. The only way to know if that feature
is available is to test for it. Then use it. And only JS can tell you
that. You are trying to test for the lack of a feature that needs the
feature to tell you if it's there or not.
Furthermore, I don't like your solution because it penalises users that
are doing the right thing - enabling javascript (well, its the right
thing in my context anyway). Those that have javascript enabled have to
send an extra request each time they want to view a new page.
If the time it takes a user's PC to process an intro page with a single
line of script is that big a deal, you are in the wrong business. Sites
redirect all the time and the delay is negligible. And most people will
simply not pay attention to it.
Secondly, I would need to rewrite all of the links throughout the site
to go to this error page, and then make the error page repost all of
the form variables. This isn't impossible, but I was hoping for an
easier, cleaner solution.
Actually, you don't. You include a snippet of script in every page that
hides a div tag wrapped inside the body, with a message above it. Script
would hide the message and show the body div. Without script, or with an
error, the user gets useful information. If your pages are server
driven, set an include to put it all there. If not, open all your static
files in something like Notetab and do a global search and replace
across all documents and replace the body tag with something like this:

<body>
<div id="noScript" style="visibility:visible">This site requires script
to be enabled. Either you have it disabled or there was a script error
on the page</div>
<div id="theBody" style="visibility:hidden">

And then replace the closing body tag with </div></body>

Then replace your closing head tag with:

<script type="text/javascript">
function showThePage(){
document.getElementById('noScript').style.visibili ty = "hidden"
document.getElementById('theBody').style.visibilit y = "visible"
}
window.onload = showThePage;
</head>

You will have problems with that if there are other onload routines though.
>Just for you though, redirecting me to a page that says "You need to
enable Javascript" would make you look pretty intelligent to users of
UA's that don't even support JS. How do you enable something the UA
doesn't support?
....
>So, what do users with Script and META disabled get???

Maybe I should have been a bit clearer. The website is targeted at a
group that is generally computer illiterate,
So you are worried about "computer illiterates" disabling a feature that
99.99% of those people don't even know exist?
meaning that probably 90% of the users will be running IE on Windows.
Probably closer to 99% of the users and 99% of those users won't even
know what JS is or how to disable it. So, you are trying to cover .01%
of your users.
The other 10% will almost definitely have some UA that does support
javascript.
Never used a Cell Phone Browser then I assume?
If not, well, you're going to have to install another browser.
Install another browser on my Cell Phone? Can you give me directions on
how to do that?
IMO, saying to your users that 'you must enable javascript', although
not ideal, is not the end of the world.
That's not what you are saying though. Think about it. "I know you are
computer illiterate and probably don't know what JS is but please enable
a feature that you don't even know what is". I don't know of a JS
browser that doesn't default to scripting enabled.
The website's functionality is a product, and like lots of software
products, there are prerequisites to running this product. We see
similar situations everyday - 'this software requires Windows',
'this software requires Linux', etc.
Daily occurrence. The difference is in how you choose to enforce that
requirement.
Having the META disabled is a problem, and was the type of information
I was looking for.
>>I came up with the idea of using a meta tag in a <noscriptsection,
and was hoping to get suggestions from this newsgroup. What I'm
suggesting is essentially:
It's a dumb idea.

Why? Constructive criticism would be nice. I think it would be a good
idea if you couldn't disable META.
Why? Half the porn sites I see start off as an innocent site that
redirects to the real porn using META redirects.
>><html>
<noscript>
<meta http-equiv="refresh" content="2;url=http://webdesign.about.com">
</noscript>

QST - do you have to put the absolute URL in, and can the time be zero?
Did you test it? I bet you didn't or you wouldn't have to ask.

I was more after what the standards say about the above attributes, and
what browser support is there for those standards and if the browsers
divert from the standards, how do they divert? I could test it in the
browsers I have, but I wanted to know how the browsers out there react.
The biggest problem with NOSCRIPT isn't support or lack of support, it
is in the inadequacy of the element. If a page has a JS error in it -
for any reason - the JS enabled browsers won't get anything but the
error message.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 2 '06 #7
No, it reacts to a confirmation of the features I want.

Which in this case, the 'confirmation of the features' is the normal
flow of the program.
In your case,
the feature you want is JS enabled. The only way to know if that feature
is available is to test for it. Then use it. And only JS can tell you
that. You are trying to test for the lack of a feature that needs the
feature to tell you if it's there or not.
Fair enough
>
Actually, you don't. You include a snippet of script in every page that
hides a div tag wrapped inside the body, with a message above it. Script
would hide the message and show the body div. Without script, or with an
...
Good idea
Probably closer to 99% of the users and 99% of those users won't even
know what JS is or how to disable it. So, you are trying to cover .01%
of your users.
I was more coming from the point that some of these people read a 'how
to secure your browser' guide or something similar, which told them to
disable javascript.
Never used a Cell Phone Browser then I assume?
The website is not suitable for the small screen sizes in Cell Phones -
we thought about this, and couldn't foresee the site being used via a
mobile phone.

Why? Half the porn sites I see start off as an innocent site that
redirects to the real porn using META redirects.
Point taken
>
The biggest problem with NOSCRIPT isn't support or lack of support, it
is in the inadequacy of the element. If a page has a JS error in it -
for any reason - the JS enabled browsers won't get anything but the
error message.
I tried this out with different js errors, and for all of the cases the
NOSCRIPT block never showed. I tried calling non-existant functions,
syntax errors in onclick handlers, and syntax errors in <scriptblocks
in the head, and none of the errors resulted in showing what was in the
NOSCRIPT block. So what errors result in the behavour described above?
I'm running FF 1.5

Taras

Nov 2 '06 #8
Taras_96 said the following on 11/2/2006 1:48 AM:

<snip>
>The biggest problem with NOSCRIPT isn't support or lack of support, it
is in the inadequacy of the element. If a page has a JS error in it -
for any reason - the JS enabled browsers won't get anything but the
error message.

I tried this out with different js errors, and for all of the cases the
NOSCRIPT block never showed. I tried calling non-existant functions,
syntax errors in onclick handlers, and syntax errors in <scriptblocks
in the head, and none of the errors resulted in showing what was in the
NOSCRIPT block. So what errors result in the behavour described above?
I'm running FF 1.5
There are three scenarios that can happen when a script page opens:

1) The script executes as expected - all is fine.
2) Script is disabled.
3) There is a script error during page load.

Script handles the first scenario.
NOSCRIPT attempts to handle the second one.

How do you deal with the third one? If Scripting is enabled, NOSCRIPT
will never show up. But if the content of the page is generated by
script and there is an error, then no content gets generated. The user
is left scratching the head and wondering "What the hell is going on?".
The snippets I gave you to use cover the third scenario. And if you
notice, my snippets don't have a NOSCRIPT element in them.

Think about an AJAX driven site (even though I am not an AJAX fan),
where the page gets created after it loads using an XMLHTTPRequest
object and the users browser doesn't support it. If the script is
written not to error out (using feature detection), then the user won't
get a page because the browser doesn't support it, they won't get the
noscript because script is enabled. The *only* solution to that is to
put the message in the page and then hide it with script.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 2 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darren Blackley | last post by:
Hi there I have documents that I want to automatically add additional meta tags to. The documents already have some meta tags and I want to keep them all together, so I want to add my new meta tags...
5
by: Wladimir Borsov | last post by:
Assume I declare at the top of a HTML page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> This refers to english HTML content/syntax. Later then I declare: <META...
6
by: MNF | last post by:
Hi everyone, I am using document.getElementById function in JavaScript to find a control within an html body, but instead I get back META item, because incidently the name of one meta tags is the...
14
by: Robert | last post by:
I have some questions about these meta tags: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> What charset should I use? Is this latin-1? I have MacOS 10.2.6. Where...
2
by: localhost | last post by:
I have these in all of my pages: <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name=vs_defaultClientScript...
4
by: Tim::.. | last post by:
Can someone please tell me why the following dynamic refresh doesn't work! Thanks Inline code... <!----- dynamically filled META REFRESH element -----> <meta id="mtaRefresh" runat="server" />...
4
by: clintonG | last post by:
Anybody know how to dynamically write the meta tags using code so they are formatted on a separate line in the HTML source? Preferred or optimal framework classes that may be used in this regard? ...
16
by: Edward | last post by:
Hi All, I am having huge problems with a very simple dotnet framework web page (www.gbab.net/ztest3.aspx) , it does NOT render correctly under Apple's Safari. The DIV's do not align amd float as...
6
by: docbook.xml | last post by:
I have the following in the XHTML 1.0 Strict page: <meta http-equiv="Content-Type" content="text/html;charset=utf-32" /> However W3 validator complains that "The character encoding specified in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.