Rendering noscript content only

Discussion in 'HTML' started by August Karlstrom, Oct 18, 2008.

  1. 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
    August Karlstrom, Oct 18, 2008
    #1
    1. Advertising

  2. August Karlstrom wrote:

    > 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.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Oct 18, 2008
    #2
    1. Advertising

  3. August Karlstrom

    richard Guest

    On Sat, 18 Oct 2008 16:08:56 +0300, "Jukka K. Korpela"
    <> wrote:

    >August Karlstrom wrote:
    >
    >> 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.


    So I have script off, how ya gonna write anything to my page?
    richard, Oct 18, 2008
    #3
  4. August Karlstrom

    richard Guest

    On Sat, 18 Oct 2008 12:15:32 +0200, August Karlstrom
    <> wrote:

    >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.
    richard, Oct 18, 2008
    #4
  5. richard wrote:
    > On Sat, 18 Oct 2008 16:08:56 +0300, "Jukka K. Korpela"
    > <> wrote:
    >
    >> August Karlstrom wrote:
    >>
    >>> 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.

    >
    > 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.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Oct 18, 2008
    #5
  6. richard wrote:
    > On Sat, 18 Oct 2008 12:15:32 +0200, August Karlstrom
    > <> wrote:
    >
    >> 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>


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

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Oct 18, 2008
    #6
  7. On 2008-10-18, Jonathan N. Little wrote:
    > richard wrote:
    >> On Sat, 18 Oct 2008 12:15:32 +0200, August Karlstrom
    >> <> wrote:
    >>
    >>> 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>

    >
    > 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.


    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Oct 18, 2008
    #7
  8. August Karlstrom wrote:
    > 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>


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Oct 18, 2008
    #8
  9. Chris F.A. Johnson wrote:

    >>>> <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>

    >>
    >> 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.


    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.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Oct 18, 2008
    #9
  10. August Karlstrom

    richard Guest

    On Sat, 18 Oct 2008 21:18:32 +0300, "Jukka K. Korpela"
    <> wrote:

    >Chris F.A. Johnson wrote:
    >
    >>>>> <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>
    >>>
    >>> 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.

    >
    >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.
    richard, Oct 18, 2008
    #10
  11. August Karlstrom

    richard Guest

    On Sat, 18 Oct 2008 18:07:49 +0000, "Chris F.A. Johnson"
    <> wrote:

    >On 2008-10-18, Jonathan N. Little wrote:
    >> richard wrote:
    >>> On Sat, 18 Oct 2008 12:15:32 +0200, August Karlstrom
    >>> <> wrote:
    >>>
    >>>> 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>

    >>
    >> 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.


    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.
    richard, Oct 18, 2008
    #11
  12. August Karlstrom

    richard Guest

    On Sat, 18 Oct 2008 14:18:08 -0400, "Jonathan N. Little"
    <> wrote:

    >August Karlstrom wrote:
    >> 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>


    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.
    richard, Oct 18, 2008
    #12
  13. richard wrote:
    > On Sat, 18 Oct 2008 18:07:49 +0000, "Chris F.A. Johnson"
    > <> wrote:


    >> 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.


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

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Oct 18, 2008
    #13
  14. richard wrote:
    > On Sat, 18 Oct 2008 14:18:08 -0400, "Jonathan N. Little"
    > <> wrote:
    >
    >> August Karlstrom wrote:
    >>> 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>

    >
    > 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.

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Oct 18, 2008
    #14
  15. Jonathan N. Little wrote:
    > August Karlstrom wrote:
    >> 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.

    [...]

    Sounds reasonable, thanks.


    August
    August Karlstrom, Oct 19, 2008
    #15
  16. August Karlstrom

    Guest

    On Oct 19, 11:29 am, August Karlstrom <> wrote:
    >
    > > 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 :(
    , Oct 19, 2008
    #16
  17. wrote:
    > 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
    August Karlstrom, Oct 19, 2008
    #17
  18. August Karlstrom

    David Mark Guest

    On Oct 18, 2:18 pm, "Jukka K. Korpela" <> wrote:

    [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');
    David Mark, Oct 29, 2008
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William.R.Reisen
    Replies:
    2
    Views:
    422
    Alan Wood
    Jul 25, 2003
  2. Burton Figg
    Replies:
    13
    Views:
    5,270
    Toby A Inkster
    Dec 31, 2003
  3. natric

    About NOSCRIPT positionning

    natric, Apr 20, 2004, in forum: HTML
    Replies:
    8
    Views:
    784
    Toby A Inkster
    Apr 26, 2004
  4. Jonathan N. Little
    Replies:
    13
    Views:
    5,640
    Jonathan N. Little
    Feb 6, 2005
  5. hazz
    Replies:
    6
    Views:
    49,415
    SkyUCHC
    Jun 9, 2010
Loading...

Share This Page