简体   繁体   English

在网站页面加载上运行Perl脚本

[英]Run a perl script on web site page load

I have a page that when loaded I would like it to run a perl script. 我有一个页面,加载后我希望它运行一个perl脚本。 Is this possible to do with javascript? 这可能与javascript有关吗? I have never ran a perl script on the web before and the only way I have seen to do it is link to it. 我以前从未在网络上运行过perl脚本,而我看到的唯一方法就是链接到该脚本。

There are 3 ways: 有3种方法:

  • If it's a dynamic page (CGI or other), as long as your script backing the page is an executable Perl script returning valid HTTP response, you're good. 如果它是动态页面(CGI或其他页面),只要支持该页面的脚本是可执行的Perl脚本,返回有效的HTTP响应,就可以了。 If you need to execute a separate Perl script, you can do it using the usual system() call (ideally, the functionality should be a Perl library call so your script can then execute it without spawning a system call). 如果您需要执行一个单独的Perl脚本,则可以使用通常的system()调用来完成(理想情况下,该功能应该是Perl库调用,以便您的脚本可以在不产生系统调用的情况下执行它)。 This approach of course works with ANY language that the back-end script is written in, eg if it's a Java Servlet, or any other code, it can also execute a system call to your Perl script. 这种方法当然适用于使用后端脚本编写的任何语言,例如,如果它是Java Servlet或任何其他代码,它也可以执行对Perl脚本的系统调用。

  • If it's a static HTML page, you can have an "onload" JavaScript event (or just a JS function call inside a <script> tag) which executes an AJAX call to a different dynamic page (say http://yourserver/scripts/run_script_X ) running the script as per previous bullet point. 如果它是静态HTML页面,则可以有一个“ onload” JavaScript事件(或<script>标记内的JS函数调用),该事件将对另一个动态页面执行AJAX调用(例如http:// yourserver / scripts / run_script_X )按照先前的要点运行脚本。

    Just to be clear, the script will be running on the web server and not in a browser/client system; 为了清楚起见,该脚本将在Web服务器上运行,而不是在浏览器/客户端系统中运行; so you need some sort of mechanism for allowing the results of the script to affect your web page if you wish to have such an effect. 因此,如果您希望产生这样的效果,则需要某种机制来允许脚本的结果影响您的网页。

     $.ajax({url: 'http://yourserver/scripts/run_script_X'}); // jQuery example 
  • As an oldie variation on the last approach, you can also have your page have a <IFRAME> whose URL points to http://yourserver/scripts/run_script_X (make the iframe small/invisible if you don't care about the results of running the script as per your comment). 作为最后一种方法的旧版本,您还可以在页面上使用<IFRAME>其URL指向http:// yourserver / scripts / run_script_X (如果您不关心iframe的结果,则将iframe设置为小号/不可见)根据您的评论运行脚本)。

     <!-- The rest of your HTML code --> <IFRAME SRC="http://yourserver/scripts/run_script_X" style="display: none;" /> 

Irelevant comment made prior to the comments on this answer : 在对此答案发表评论之前先发表Irelevant评论

Without a lot more context on what you want the page to be (CGI script, static HTML, etc...) and what you want the script to do and how you want the results of running the script to affect your page, it's hard to suggest anything more precise. 如果没有更多关于所需页面(CGI脚本,静态HTML等)的上下文,以及想要脚本执行的操作以及运行脚本的结果如何影响页面的方式,这很难提出更精确的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM