how to get visitor browser window size in perl CGI

2019-07-25 02:04发布

问题:

Does anyone know how to get the height and width of user's browser window in a Perl CGI script?

Or how can i pass this value to my $var from javascript or other languages ???

回答1:

If you're talking about a perl script that gets called via a form and then prints a web site, you can use javascript to get the browser size, put it into hidden form variables and retrieve them with CGI in your perl script. It can then react to the values, e.g. change the size of a static piece of web layout.

On the web site, use javascript like this:

<script type="text/javascript">
document.forms[0].windowheight.value = window.innerHeight;
document.forms[0].windowwidth.value = window.innerWidth;
</script>

But keep in mind that different browsers use different ways in JS to get the size values. Maybe this helps. You could also use jQuery to determine these values.

When you have them in your <form> and submit it, you can use the CGI module to read them just the same as all the other form parameters. It doesn't matter if they were sent via POST or GET.

use strict;
use warnings;
use CGI;
my $cgi = CGI->new;
my $windowHeight = $cgi->param('windowheight');
my $windowWidth = $cgi->param('windowwidth');