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

I have written a Perl CGI script that takes a search string from the user, searches for the string in an index file of documents, and returns an HTML page of results. The posted results are links to matching documents, and the user is to be given a choice of which of these documents he wants to retrieve. Clicking on a link should popup the Open Document window that offers the user the choice of opening the document with the appropriate application, or else Saving the document. The problem is that when the links are posted on the results page, no action takes place when the user clicks on a link. BUT - if I save the generated page source into a file and then open that file, it works just fine.

Here is a sample of the generated HTML code:

<TD align=left><a href="file:/net/server/Docs/doc03.pdf">pdf</a></TD>

Here is the HTML code that invokes the Perl CGI script:

<FORM ACTION="/cgi-bin/swin_search.cgi" METHOD=POST> <B>Search string:</B> &nbsp; <INPUT type=text NAME=Query1 SIZE=35 MAXLENGTH=100> <BR><BR> <INPUT type=submit value=" RETRIEVE SEARCH RESULTS "> <INPUT type=reset value=" CLEAR "> </FORM>

And if it's of any use, here are the opening lines of the Perl script:

require 5.003; use CGI qw( :standard :html3 );

Thanks for any eye-opening pointers.

Replies are listed 'Best First'.
Re: Can't get Open Document popup window to appear
by Corion (Patriarch) on Sep 22, 2011 at 20:00 UTC

    Are you sure your browser is configured to allow following to local file:// URIs from non-file:// URIs? At least Firefox does not do so by default. I think you will either have to have all your links be http:// links or have to reconfigure your browser to allow file:// URIs. Note that opening arbitrary local file:// URIs is considered a security hole and thus, most browsers disallow this.

    Also see this Mozilla KB entry for how to reconfigure Firefox. Not that I recommend doing so, at least not for a browser that is to be used outside of a local intranet.

      Thank you for your response. I'm not certain that this could be the problem, since as I mentioned (briefly in passing), when I save the generated source code into a file (using "View Page Source") and the plug that code into the browser, everything works exactly the way I need it to. It only fails when I am using the generated code from the Perl script, which was created with the PRINT command:

      print "<a href=\"file:$filepath$path_ext\">$format</a></TD>\n";

      resulting in this line in the HTML code:

      <a href="file:/net/server/Docs/02.pdf">pdf</a></TD>

      If the browser will not accept following to local file:// URIs, then why would this succeed when it comes from a source code file instead of automatically generated code?

        Where do you save your file? If a page is served over the http protocol, it cannot open file URIs local to the client. If you "save the page" locally and then open it by double-clicking, you open the page as a local file. Local files are allowed to open other local files. Save your page and upload it to your webserver. If the static page works from there, your problem is elsewhere. If the static page fails in the same way your Perl script fails, the error is as I said.