Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I can't work out how to use the noscript tag with cgi.pm version 3.55

In the docs, noscript is defined in the 'Creating the Header' section, but the noscript html tag should not be put in the html header AFAIK

Has anyone got a working example, or is this a bug?

Replies are listed 'Best First'.
Re: cgi.pm and noscript
by moritz (Cardinal) on Sep 18, 2011 at 13:08 UTC

      OK thanks

      I was trying noScript (which is how its written in the docs)

        The documentation just mentions -noScript as an option, and then talks about methods and subs for standard HTML tags in the section CREATING STANDARD HTML ELEMENTS, though it doesn't mention the noscript tag by name.

Re: cgi.pm and noscript
by Khen1950fx (Canon) on Sep 18, 2011 at 13:20 UTC
    see:

    NOSCRIPT.

    You can put it in the HTML header, but not the HTTP header.

    Update: Here's an example:

    #!/usr/bin/perl use strict; use warnings; print <<"End_Text"; <SCRIPT LANGUAGE=JAVASCRIPT> <!-- document.write('<img src="/cgi-bin/get-img.cgi?'+document.referrer+'"a +lt="logo" height=103 width=419>') // --> </SCRIPT> <NOSCRIPT> <img src="/cgi-bin/get-img.cgi?noscript" alt="logo" height=103 width=4 +19> </NOSCRIPT> End_Text
Re: cgi.pm and noscript
by ww (Archbishop) on Sep 18, 2011 at 13:52 UTC
    Perhaps you should be explicit about what you're trying to do. What scripting language are you trying to use to which you want the noscript to apply and how are you trying to call the script?

    My best guess, based on your second para, is that you have a script (js, VB, tcl or whatever) in the head section of a page generated by a perl script and that you're trying to execute the script or the content of the noscript element when the page is loaded.

    Update: Off on the wrong, Wrong, WRONG! track.

    The noscript tag is used to provide some sort of alternate info for browsers (intrinsicly or because of a user-selected option) which won't execute the script. But the noscript has to be in the body since it won't be executed if it's in the head section. TTBOMK (and recollection ... and sticking to js for this comment), in the case of an "onload" inside the <body...> tag, HTML provides no way to apply a <c>noscript alternate.

    OTOH, if you've inserted your script in-line, it appears that noscript should work if placed immediately after the script; substitute "might" for "should" if your script is in the head or an external file (and, in either case, remember that HTML doesn't allow noscript inside a <p>...</p> construct.

    IMO, §18 of the w3c guide on scripts doesn't provide a satisfactorily explicit answer to your question and the doc for CGI.pm that's distributed with 5.12 effectively tosses the question back to w3c...

    But this is based on way-too-much guesswork. Tell us more.

      I was looking for an alternative to my current method which is

      $cgi->start_html( ... -script => {-language => 'javascript', -src => '../javascript/sc +ript.js'}, -onLoad => 'init()', ),

      where script.js contains

      function init() { document.getElementById('jsDisabled').style.display = 'none'; }

      which hides a message about javascript being disabled, but sometimes it briefly appears on the page, so I wondered if using the noscript tag would improve on that.