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

Hi, I have a very basic question: In the web application that I am working on, there is a tmpl file in which users can click on hyperlinks in lists to view more details. The problem is-when they click on a hyperlink-the details display in the same window-and if they click Back to go back to the result list-they see the "Page has expired" message. I know about the JS window.open() function for displaying links in a new window-what I don't know is where and how to implement it in the way I have things coded (See code below):
In Results.tmpl: This is the hyperlink that they click to view more information: <a href="javascript:createDispatch(<!-- TMPL_VAR NAME=myNo -->);" ><!- +- TMPL_VAR NAME=myNo --></a> The hyperlink goes to this JS function: function createDispatch(subNo) { document.resultsForm.subNumber.value=subNo; document.resultsForm.submit(); } The submit action above calls a CGI file to retrieve the required deta +ils: <form method="POST" name="resultsForm" action = "../cgi-bin/prepareDis +patch.cgi"> The prepareDispatch.cgi file retrieves details and displays them in Di +spatchForm.tmpl
My question is: How and where should I specify that DispatchForm.tmpl should display in a new window?

Replies are listed 'Best First'.
Re: Displaying cgi-tmpl file in new window
by jZed (Prior) on Jul 07, 2004 at 17:15 UTC
    Specify a TARGET="windowname" attribute in the anchor.
      Specifically, target="_blank".

      John

        Alrite-I tried adding a target="_blank" attribute to my anchor tag. A new window is launched but with the "Page cannot be displayed" message. The address in the browser shows "javascript:createDispatch(xxxx)" where xxx is the value I passed.
        Looks like execution of the JS function is not completed-no cgi script is called when I add the target attr. The browser just tries to display the JS function.
        Suggestions?
Re: Displaying cgi-tmpl file in new window
by wfsp (Abbot) on Jul 07, 2004 at 18:25 UTC
    I find it easier to open a new window with javascript, you can set the size, and, perhaps, pass a query holding your variable.
    Call your cgi script during the onload event.
    There is more than one way to do it though.
    There are many js tutorials (1000's) that can help you and it would be a waste duplicating it here.
    Google is your friend!
    wfsp
      Yeah-I do rely on Google a lot-I just don't know what to search on here.
      The way I understand your response-can you confirm this is what you are saying:
      1. In the anchor tag, call a windowOpen JS function (pass hidden parameter value to it, say 'Temp').
      2. In the windowOpen JS function:
      a)Set hidden variable to the passed value (MyVar=Temp)
      b)Call window.open and customize
      c)Set window.onLoad = <path to my cgi file>
      In this case, will the variable MyVar still be accessible in the CGI script?
      Thanks!
        Set window onload to call a function. This would tack a '?' and the variable (having escaped it) onto the end of the cgi filename. Call the script.
        'javascript tutorial window.open' would give you a good start.
        wfsp

        update:
        I've posted a script you could use in the question you posted to devshed.
        Thankfully, it is very similar to the other reply. I'm not completly mad yet!
        Apologies to all for any OT infringments
        wfsp

Re: Displaying cgi-tmpl file in new window
by pearlie (Sexton) on Jul 08, 2004 at 05:18 UTC
    Specify name of the script that you want to call on submit in a href itself and pass the variable as a parameter using ? format as follows: <a href="name of script"?param name=<TMPL_VAR NAME="value"> This must solve your purpose.
      I tried all suggested solutions-each of them has it's own problem. I am posting the summary here-in the hope that someone can help me get one of them working:

      1. Specify target="_blank" in anchor tag-
      No page is displayed-cgi script does not get called.

      2. Specify target="_blank" in <form> tag-
      Seems to be my best option so far-displays in a new window but I cannot customize the window.

      3. Call openWindow function. In openWindow function:
      pageURL = eval("http:\/\/127.0.0.1\/cgi-bin\/prepareDispatch.cgi?subNu +mber="+subNo+"&whichForm=Dispatch"); popupwin = window.open(pageURL,'','toolbar=no,scrollbars=yes,location= +no,width=' + 800 + ',height=' + 650); popupwin.focus();
      In the above code, pageURL is returned as undefined. The eval function is fine-I checked that on a website but pageURL is not initialized to whatever the eval function returns. So far, the second option seems to be working except that I'd like to take this one step further and customize the target window-for which I need to get pageURL above initialized. Comments? Thanks!
        See the update to my reply above.
        wfsp