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

Hopefully a simple question for the masters.... I'm writing a cgi program, and need to add: onLoad="javascript:JSname();" to the <body> tag during the start_html process, so that it will generate this: <body onLoad="javascript:JSname();"> I've tried searching for start_html examples that would show this, but no luck.
  • Comment on Using CGI's start_html to add attributes to <body>

Replies are listed 'Best First'.
Re: Using CGI's start_html to add attributes to <body>
by kejohm (Hermit) on Jul 22, 2011 at 06:04 UTC

    Use the -onLoad parameter for start_html(), eg.

    start_html(-onLoad => "javascript:JSname();");

    Check out the docs for more details.

      The javascript: label inside the event handler is cargo cult nonsense, drop it.

      The only place where the javascript: prefix once made sense was in the href attribute of an a element (i.e. <a href="javascript:foo()">...</a>), where it was interpreted as a pseudo-protocol. This was needed for Netscape Navigator < 2.0, Internet Explorer < 3.0, Opera < 5.12, and other long forgotten software from the dawn of the WWW decades ago, lacking the standard onclick event handler.

      For modern web pages, don't insert any Javascript at all into the HTML document, load it from an external resource and use DOM methods to add event handlers. Libraries like jQuery make this much easier than coding everything manually.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: Using CGI's start_html to add attributes to <body>
by Wolfman (Initiate) on Jul 22, 2011 at 01:37 UTC