NAME
HTML::Native::JavaScript - embedded JavaScript code
SYNOPSIS
use HTML::Native::JavaScript;
my $external_js =
HTML::Native::JavaScript->new ( { src => "script.js" } );
print $external_js;
# prints "<script src="script.js" type="text/javascript"></script>"
my $inline_js = HTML::Native::JavaScript->new ( <<'EOF' );
document.write("<b>Hello World</b>");
EOF
print $inline_js;
# prints:
# <script type="text/javascript">//<![CDATA[
# document.write("<b>Hello World</b>");
# //]]></script>
DESCRIPTION
An HTML::Native::JavaScript object represents a piece of JavaScript code, either external or inline. It generates the <script>
tag, and will wrap inline JavaScript code inside //<![CDATA[
and //]]>
markers to ensure correct interpretation by both HTML and XHTML parsers.
METHODS
new()
$elem = HML::Native::JavaScript->new();
$elem = HML::Native::JavaScript->new ( { <attributes> } );
$elem = HML::Native::JavaScript->new ( <inline script> );
$elem = HML::Native::JavaScript->new ( { <attributes> },
<inline script> );
Create a new HTML::Native::JavaScript object, representing a single <script>
element.
The attribute type="text/javascript"
will be added automatically if not explicitly specified.