Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / HTML / October 2008



Tip: Looking for answers? Try searching our database.

Rendering noscript content only

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
August Karlstrom - 18 Oct 2008 11:15 GMT
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
Jukka K. Korpela - 18 Oct 2008 14:08 GMT
> 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.

Signature

Yucca, http://www.cs.tut.fi/~jkorpela/

richard - 18 Oct 2008 18:17 GMT
>> Anyway, I'm making a site
>> that relies on JavaScript; however, if JavaScript is not enabled I
[quoted text clipped - 20 lines]
>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?
Jonathan N. Little - 18 Oct 2008 19:01 GMT
>>> Anyway, I'm making a site
>>> that relies on JavaScript; however, if JavaScript is not enabled I
[quoted text clipped - 19 lines]
>
> 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.

Signature

Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

richard - 18 Oct 2008 18:23 GMT
>Hi,
>
[quoted text clipped - 30 lines]
>
>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.
Jonathan N. Little - 18 Oct 2008 19:04 GMT
>> Hi,
>>
[quoted text clipped - 33 lines]
> 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? ;-)

Signature

Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Chris F.A. Johnson - 18 Oct 2008 19:07 GMT
>>> Hi,
>>>
[quoted text clipped - 36 lines]
> 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.

Signature

  Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
  ===================================================================
  Author:
  Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Jukka K. Korpela - 18 Oct 2008 19:18 GMT
>>>> <p>This site requires a JavaScript enabled browser.</p>
>>>> </noscript>
[quoted text clipped - 12 lines]
>
>   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.

Signature

Yucca, http://www.cs.tut.fi/~jkorpela/

richard - 18 Oct 2008 21:21 GMT
>>>>> <p>This site requires a JavaScript enabled browser.</p>
>>>>> </noscript>
[quoted text clipped - 30 lines]
>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.
David Mark - 29 Oct 2008 05:55 GMT
[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');
richard - 18 Oct 2008 21:24 GMT
>>>> Hi,
>>>>
[quoted text clipped - 38 lines]
>
>   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.
Jonathan N. Little - 18 Oct 2008 23:18 GMT
>>   He didn't say "redirect", he said "direct", e.g., put a link.
>
[quoted text clipped - 3 lines]
> 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.

Signature

Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

Guy Macon - 19 Oct 2008 19:30 GMT
>Of course, one should properly educate themselves and find out from
>various sources [...] before mouthing off.

You haven't hung around Usenet Newsgroups much, have you? <grin>

Signature

Guy Macon
<http://www.GuyMacon.com/>

Jonathan N. Little - 18 Oct 2008 19:18 GMT
> 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>

Signature

Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

richard - 18 Oct 2008 21:26 GMT
>> Hi,
>>
[quoted text clipped - 28 lines]
></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.
Jonathan N. Little - 18 Oct 2008 23:24 GMT
>>> Hi,
>>>
[quoted text clipped - 32 lines]
> 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.

Signature

Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com

August Karlstrom - 19 Oct 2008 11:29 GMT
>> Hi,
>>
[quoted text clipped - 8 lines]
> the page the NON-JavaScript page and use JavaScript to redirect to the
> JavaScript-Required page.
[...]

Sounds reasonable, thanks.

August
mynameisnobodyodyssea@googlemail.com - 19 Oct 2008 16:50 GMT
> > 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
[quoted text clipped - 5 lines]
>
> 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 :(
August Karlstrom - 19 Oct 2008 18:37 GMT
> Keep in mind that search engines cannot usually follow
> (and do not like very much) JavaScript redirects,
[quoted text clipped - 8 lines]
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.