in reply to Separate Javascipt code from pure Perl code
It seems that you want to set a variable for your char_by_chars.js script file.
You can't shoehorn a variable's content into a file that is referenced by the browser via a src attribute, other that opening this file, writing the variable's content to it, and close the file. Which surely is not what you want.
But you can include verbatim Javascript with the content of a variable in your page, before the directives containing src tags:
my $data = 'Some text in a variable defined before loading script file +s'; print start_html( -script => [ "var textToShow = '$data';\n", { -language => 'JAVASCRIPT', -text => "var textToShow = \"$data\";", }, { -language => 'JAVASCRIPT', -src => '/data/scripts/char_by_char.js' }, { -language => 'JAVASCRIPT', -src => '/data/scripts/orderlist.js' } ], -style => '/data/scripts/style.css', -title => 'Order Project!' ); __END__ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Order Project!</title> <link rel="stylesheet" type="text/css" href="/data/scripts/style.css" +/> <script type="text/javascript">//<![CDATA[ var textToShow = 'Some text in a variable defined before loading scrip +t files'; //]]></script> <script type="text/javascript"></script> <script src="/data/scripts/char_by_char.js" type="text/javascript"></s +cript> <script src="/data/scripts/orderlist.js" type="text/javascript"></scri +pt> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body>
Since your variable textToShow thusly is defined before loading any JavaScript file, It will be available to your functions inside those files - if you don't re-define that variable in your JavaScript file, that is.
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Separate Javascipt code from pure Perl code
by Nik (Initiate) on May 07, 2007 at 18:48 UTC | |
by shmem (Chancellor) on May 07, 2007 at 21:43 UTC | |
|