Rendering noscript content only

A

August Karlstrom

Hi,

This is probably a rather basic question. Anyway, I'm making a site that
relies on JavaScript; however, if JavaScript is not enabled I want to
show some information instead of the regular content. What is the
recommended way to achieve this?

For example if JavaScript is not enabled the HTML below will output

This site requires a JavaScript enabled browser.

This is the regular content.

but I want only the first paragraph to be rendered in this case.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Test</title>
<script type="text/javascript"></script>
</head>

<body>
<noscript>
<p>This site requires a JavaScript enabled browser.</p>
</noscript>

<p>This is the regular content.</p>
</body>
</html>


August
 
J

Jukka K. Korpela

August said:
Anyway, I'm making a site
that relies on JavaScript; however, if JavaScript is not enabled I
want to show some information instead of the regular content.

Do you think there is some useful information to be given?
For example if JavaScript is not enabled the HTML below will output

This site requires a JavaScript enabled browser.

Do you think that's useful information? To whom, and why? If I have turned
off JavaScript for security reason, should that make me turn it on now? What
if company policy has turned it off? Well, I might visit the site on my home
computer later. Would I do that just because the site says it requires a
JavaScript enabled browser?
This is the regular content.

but I want only the first paragraph to be rendered in this case.

Then you should make the "regular content" JavaScript-generated. The old way
is to use document.write(), but especially if you are using XHTML, for some
odd or even reason, you should instead manipulate the document tree using
"standard" DOM tools.
 
R

richard

Do you think there is some useful information to be given?


Do you think that's useful information? To whom, and why? If I have turned
off JavaScript for security reason, should that make me turn it on now? What
if company policy has turned it off? Well, I might visit the site on my home
computer later. Would I do that just because the site says it requires a
JavaScript enabled browser?


Then you should make the "regular content" JavaScript-generated. The old way
is to use document.write(), but especially if you are using XHTML, for some
odd or even reason, you should instead manipulate the document tree using
"standard" DOM tools.

So I have script off, how ya gonna write anything to my page?
 
R

richard

Hi,

This is probably a rather basic question. Anyway, I'm making a site that
relies on JavaScript; however, if JavaScript is not enabled I want to
show some information instead of the regular content. What is the
recommended way to achieve this?

For example if JavaScript is not enabled the HTML below will output

This site requires a JavaScript enabled browser.

This is the regular content.

but I want only the first paragraph to be rendered in this case.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Test</title>
<script type="text/javascript"></script>
</head>

<body>
<noscript>
<p>This site requires a JavaScript enabled browser.</p>
</noscript>

<p>This is the regular content.</p>
</body>
</html>


August

You can direct those with script off to a more friendly page.
such as <noscript> direct to page 2</noscript>
Or
Have a text link to the noscript page.

But with more modern browsers, you get told fairly easily if the page
isn't kosher scripting and trying to install something like a virus or
malware. Statistics show that 10% or less turn off script. I would
venture a guess and say that a vast majority don't even know how to
turn it off.
 
J

Jonathan N. Little

richard said:
So I have script off, how ya gonna write anything to my page?

You won't, you will only get what is in the NOSCRIPT element which is
what the OP wanted...reread.
 
J

Jonathan N. Little

richard said:
You can direct those with script off to a more friendly page.
such as <noscript> direct to page 2</noscript>

And how do you propose to do the redirect within the noscript element?
JavaScript? ;-)
 
C

Chris F.A. Johnson

And how do you propose to do the redirect within the noscript element?
JavaScript? ;-)

He didn't say "redirect", he said "direct", e.g., put a link.
 
J

Jonathan N. Little

August said:
Hi,

This is probably a rather basic question. Anyway, I'm making a site that
relies on JavaScript; however, if JavaScript is not enabled I want to
show some information instead of the regular content. What is the
recommended way to achieve this?
<snip>

The most efficient way to do this is to turn the problem around. Make
the page the NON-JavaScript page and use JavaScript to redirect to the
JavaScript-Required page.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-us">

<title>JavaScript Warning</title>

<script type="text/javascript">
//redirection will only happen if JavaScript is enabled
window.location.href="JS_REQ_PAGE.html";
</script>

</head>
<body>
<p>Message warning that JavaScript is required to use your site.</p>
</body>
</html>
 
J

Jukka K. Korpela

Chris said:
He didn't say "redirect", he said "direct", e.g., put a link.

That's absurd. Saying "This site requires a JavaScript enabled browser." is
bad, and using a link to a useable page is somewhat better, but why on
%Planet; would you tell the user go somewhere to get the content when you
can put that content in the <noscript> element?

Alternatively, you could write the more friendly content as normal content
of the page and use JavaScript redirect, such as
<script type="text/javascript">
document.location.href = 'foobar.html';
</script>
e.g. at the very start of the <head> element content, to send
JavaScript-enabled browsers directly to the JavaScript-dependent page
foobar.html.

Of course the normal sensible approach is to write the normal content first,
then add JavaScript functionality to it in a manner that does not break the
page content when JavaScript is off. Then you don't need any of the above.
 
R

richard

That's absurd. Saying "This site requires a JavaScript enabled browser." is
bad, and using a link to a useable page is somewhat better, but why on
%Planet; would you tell the user go somewhere to get the content when you
can put that content in the <noscript> element?

Alternatively, you could write the more friendly content as normal content
of the page and use JavaScript redirect, such as
<script type="text/javascript">
document.location.href = 'foobar.html';
</script>
e.g. at the very start of the <head> element content, to send
JavaScript-enabled browsers directly to the JavaScript-dependent page
foobar.html.

Of course the normal sensible approach is to write the normal content first,
then add JavaScript functionality to it in a manner that does not break the
page content when JavaScript is off. Then you don't need any of the above.


Which is why I try to make my pages useable without scripting.
Witout script, you just get a longer presentation.
A page I'm working on now uses script only to make presentation
better. It will work just fine without script.
 
R

richard

He didn't say "redirect", he said "direct", e.g., put a link.

Thanks for the clarification.
Of course, one should properly educate themselves and find out from
various sources just how the tag works before mouthing off.
Say you had <noscript>www.google.com</script>.
So if script is off, you get sent to google.
 
R

richard

<snip>

The most efficient way to do this is to turn the problem around. Make
the page the NON-JavaScript page and use JavaScript to redirect to the
JavaScript-Required page.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-us">

<title>JavaScript Warning</title>

<script type="text/javascript">
//redirection will only happen if JavaScript is enabled
window.location.href="JS_REQ_PAGE.html";
</script>

</head>
<body>
<p>Message warning that JavaScript is required to use your site.</p>
</body>
</html>

With the noscript thing in the head, why would you say anything on the
main page?
If script is on, then you'd see it. Pointless.
 
J

Jonathan N. Little

richard said:
On Sat, 18 Oct 2008 18:07:49 +0000, "Chris F.A. Johnson"


Thanks for the clarification.
Of course, one should properly educate themselves and find out from
various sources just how the tag works before mouthing off.
Say you had <noscript>www.google.com</script>.
So if script is off, you get sent to google.

No you won't! You will just see the text "www.google.com" on the page.
 
J

Jonathan N. Little

richard said:
With the noscript thing in the head, why would you say anything on the
main page?
If script is on, then you'd see it. Pointless.

First of all <noscript> is not allowed in the head.

Second, you seem to suggest that putting a URL in a <noscript> will
somehow direct the browser to that url. It won't.

Third, one would only see this page above IF JavaScript was disabled,
else it would display with the warning message that the OP wanted
without the stuff from the JavaScript-enabled
content which the OP also wanted.
 
A

August Karlstrom

Jonathan said:
<snip>

The most efficient way to do this is to turn the problem around. Make
the page the NON-JavaScript page and use JavaScript to redirect to the
JavaScript-Required page.
[...]

Sounds reasonable, thanks.


August
 
M

mynameisnobodyodyssea

The most efficient way to do this is to turn the problem around. Make
the page the NON-JavaScript page and use JavaScript to redirect to the
JavaScript-Required page.

[...]

Sounds reasonable, thanks.

August

Keep in mind that search engines cannot usually follow
(and do not like very much) JavaScript redirects,
so if you have a URL reachable
only via JavaScript redirect in the <script>
element of other pages,
it might not be indexed in search results.

If there are non-JavaScript crawlable links to both URLs,
(one URL with some JavaScript and the other without),
but with similar crawlable content,
then search engines might crawl both URLs and
find duplicate-ish content :(
 
A

August Karlstrom

Keep in mind that search engines cannot usually follow
(and do not like very much) JavaScript redirects,
so if you have a URL reachable
only via JavaScript redirect in the <script>
element of other pages,
it might not be indexed in search results.

If there are non-JavaScript crawlable links to both URLs,
(one URL with some JavaScript and the other without),
but with similar crawlable content,
then search engines might crawl both URLs and
find duplicate-ish content :(

OK, thanks for the info. I now consider adding JavaScript in an
unobtrusive way instead.

http://en.wikipedia.org/wiki/Unobtrusive_JavaScript


August
 
D

David Mark

[snip]
Of course the normal sensible approach is to write the normal content first,
then add JavaScript functionality to it in a manner that does not break the
page content when JavaScript is off. Then you don't need any of the above..

Right. And both examples of scripted redirection in this thread will
break the back button. If one really needs to redirect via client
side script, use:

window.location.replace('alternateversion.html');
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top