I want to pop up a quick error dialog from inside a perl cgi script so as
to avoid reloading the whole page with an error message. It can be done
in easily javascript, but the size and complexity of my cgi programming
is too much for javascript; it has to be done in perl.
Yet, since it's so easily done in javascript, I figured I could just
make a quick print statement to the browser.
Follow me on this: I can type the following in the Location bar of my browser:
javascript:alert('hello')
And I will get a popup box that says "hello". So, how can you write a print
statement from within a perl cgi script that does essentially that?
I've tried various experiments, starting with the obvious:
sub alert
{
print "javascript:alert('hello')\n\n";
}
It does nothing. No error, but no result. The page is simply cleared, and
that's the end.
Obviously, the right header needs to be printed. But what?
I looked at the docs, and the best I could find was something like this:
sub alert
{
$msg = shift;
$msg =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
print $query->header(-script=>"alert('$msg')");
}
But, this doesn't work either.
If there's an answer to this, my next question will be:
Is there a version that blocks (or doesn't)?
(blocking in the sense that it waits for the box to be dismissed)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.