Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Keep It Simple, Stupid
 
PerlMonks  

javascript inside HTML::Template file

by kulls (Hermit)
on Nov 16, 2012 at 08:37 UTC ( #1004151=perlquestion: print w/ replies, xml ) Need Help??
kulls has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have the below HTML::Template file,
<div id="Div90">sample</div> <script> alert('hai'); </script>
After, I render  $template->output() , It does not execute the script tag.
Any suggestion on this ?
-Raja

Comment on javascript inside HTML::Template file
Select or Download Code
Re: javascript inside HTML::Template file
by Anonymous Monk on Nov 16, 2012 at 08:58 UTC

    It does not execute the script tag. Any suggestion on this ?

    Its got nothing to do with perl. If you want to know why a browser doesn't execute javascript, ask the browser.

Re: javascript inside HTML::Template file
by marto (Chancellor) on Nov 16, 2012 at 09:32 UTC

    Not a perl question. Please learn basic JavaScript and HTML.

Re: javascript inside HTML::Template file
by space_monk (Chaplain) on Nov 16, 2012 at 10:20 UTC

    There are so far as I know no problems with having Javascript in an HTML template. However you should show the critical parts of your program to make it a Perl question rather than a "what's wrong with this page" problem.

    It may be as simple as your web browser blocking active content.

    A Monk aims to give answers to those who have none, and to learn from those who know more.
Re: javascript inside HTML::Template file
by Anonymous Monk on Nov 16, 2012 at 12:48 UTC
    The server does not execute the javascript: the client does. Observe the site in action. The javascript is part of the page-content that is delivered to the client: it is executed there, as the page-content may direct..
Re: javascript inside HTML::Template file
by ColonelPanic (Friar) on Nov 16, 2012 at 13:29 UTC

    CGI programs are a multi-level, multi-language endeavor. You have three different languages (Perl, HTML, and Javascript) and two different environments (server and browser). An error or setting in just one of these can cause the whole thing to fail.

    In order to successfully debug a problem like this, you have to divide and conquer. Perform simple tests that verify that just one part of the equation is working correctly. That will let you narrow down where the real problem is.

    Some examples of tests you might perform:

    • View source in your browser. Has your script generated the page as you expect?
    • Create a simple HTML file with a simple Javascript command by hand. Does the Javascript execute?
    • Hand-create a simple HTML file with the exact Javascript code you want to use. Does this execute in the browser?
    • Have your Perl script output a very simple HTML file with a simple Javascript command. Does this work?
    • Test some of the features you want to use in a regular Perl script before putting them into a server environment.
    And so on. In this way you can figure out exactly where the problem is. If you still can't get it to work, you will at least have learned enough to post a specific, well-informed question.



    When's the last time you used duct tape on a duct? --Larry Wall
Re: javascript inside HTML::Template file
by NetWallah (Monsignor) on Nov 16, 2012 at 16:27 UTC
    Consider adding a <noscript> element to show an appropriate message if the browser does not support javascript.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

Re: javascript inside HTML::Template file
by sundialsvc4 (Monsignor) on Nov 16, 2012 at 23:01 UTC

    Remember that the mere presence of a script-tag does not mean that the contents of the tag will be immediately executed by the browser.   Most browsers have a debugger, either built-in or as a plugin.   (You might have to click on an intentionally-obscure preferences checkbox to turn it on...)   Armed with this information, you can see what the browser is doing.   As others have said, tutorial/background info about the subject might be needed ... and <understatement size="infinity">not all browsers (heh...) are the same.</understatement>

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1004151]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-04-23 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (555 votes), past polls