472,983 Members | 2,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Passing a Java variable to local PHP script.

Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.

I have a feeling, this will not be easy - as java is client- and php
server-sided. Now, if my assumption is corect, then it will be
neccessary to generate the page via .php on the webserver and send it
to the browser. Once loaded, java will be executed to aquire the used
screen resolution. These values (height/width) will have to be
returned to the server, prob. via post. The server will now have to
acknowledge the presence of these values and regenerate the webpage
once more, this time using the provided values.

I hope I've got it so far. Problem is - I don't have a clue about java
and only basics in php. Please help me get this accomplished, abd
don't forget: I'm not java savy.

kind regards,

Andy R.
Jul 17 '05 #1
4 3421
Andy R. wrote:
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.


Firstly JavaScript != Java, they just share a name.

What you need to do is send a 'detect' page if you don't already know
the screensize. This will redirect to the original page passing the
screen size.

Create a file called screensize.php.
<?php
if ($_GET['screensize']) {
$_SESSION['screensize'] = $_GET['screensize'];
}

if (!$_SESSION['screensize']) { ?>
<html>
<head>
<script language=javascript>
window.location.href="<?=$PHP_SELF?>?screensize=" +
screen.width + "x" + screen.height;
</script>
</head>
<body>
Checking screen size
</body>
</html>
<?php exit();
} ?>

Then just include('screensize.php'); at the top of your pages. All of
them will have $_SESSION['screensize'] set for you.

NOTE: the user may not have their browser full screen.
Jul 17 '05 #2
"Andy R." <No*******@mailinator.com> wrote in message
news:93**************************@posting.google.c om...
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.

I have a feeling, this will not be easy - as java is client- and php
server-sided. Now, if my assumption is corect, then it will be
neccessary to generate the page via .php on the webserver and send it
to the browser. Once loaded, java will be executed to aquire the used
screen resolution. These values (height/width) will have to be
returned to the server, prob. via post. The server will now have to
acknowledge the presence of these values and regenerate the webpage
once more, this time using the provided values.

I hope I've got it so far. Problem is - I don't have a clue about java
and only basics in php. Please help me get this accomplished, abd
don't forget: I'm not java savy.

kind regards,

Andy R.


Don't reload the page, load a blank image,

<IMG SRC="blank.gif" NAME="imgscreensize">

<SCRIPT>
// do you stuff here
imgtime.src = "screensize.php?w=" + varWidth + "&h=" + varHeight;
</SCRIPT>
then have screensize.php do something like this
<?php

// log your stuff here

header("Content-type: image/gif");
readfile("blank.gif");
?>
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3

Uzytkownik "Kevin Thorpe" <ke***@pricetrak.com> napisal w wiadomosci
news:40***********************@news.easynet.co.uk. ..
Create a file called screensize.php.
<?php
if ($_GET['screensize']) {
$_SESSION['screensize'] = $_GET['screensize'];
}

if (!$_SESSION['screensize']) { ?>
<html>
<head>
<script language=javascript>
window.location.href="<?=$PHP_SELF?>?screensize=" +
screen.width + "x" + screen.height;
</script>
</head>
<body>
Checking screen size
</body>
</html>
<?php exit();
} ?>


Consider using window.location.replace(url) instead, so that the back button
behaves more reasonably.

Jul 17 '05 #4
Hi Andy,

Assuming you only need to adjust the size of some html elements to the
screen size, you could do resizing entirely in javascript by something like:

<HTML><HEAD></HEAD>
<BODY onResize="scaleContent()>
<script>
function scaleContent() {

getElement('itemTableDiv').style.height=(window.do cument.body.clientHeight)-179;
getElement('itemTableDiv').style.width=(window.doc ument.body.clientWidth)-130;
}

function getElement( elementId)
{
var element;

if (document.all) {
element = document.all[elementId];
}
else if (document.getElementById) {
element = document.getElementById(elementId);
}
else element = -1;

return element;
}
</script>

<div id=itemTableDiv style='height: 300px; width: 600px; overflow:
auto;' valign='top'>
<?php printItemTablePart() ?>
</div>
<script> scaleContent(); </script>
</BODY>
</HTML>

This resizes a DIV according to screen size minus (130, 179). You can
fill in different values to make it larger or smaller, or print the
proper values from php. It works in recent versions of both IE and
Mozilla, (not in Nescape 4.x). Of course you need to write the
printItemTablePart() function in php to produce the content of the div,
or just print it some other way from php.

This javascript will probably work on other types of html elements too,
as long as you give each one a different id, and as long as the scaling
is not making them too small for their own elements to fit in. Be aware
that the second script must be AFTER the definition of the elements that
are resized and after the functions that are called.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org
Andy R. wrote:
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.

I have a feeling, this will not be easy - as java is client- and php
server-sided. Now, if my assumption is corect, then it will be
neccessary to generate the page via .php on the webserver and send it
to the browser. Once loaded, java will be executed to aquire the used
screen resolution. These values (height/width) will have to be
returned to the server, prob. via post. The server will now have to
acknowledge the presence of these values and regenerate the webpage
once more, this time using the provided values.

I hope I've got it so far. Problem is - I don't have a clue about java
and only basics in php. Please help me get this accomplished, abd
don't forget: I'm not java savy.

kind regards,

Andy R.


Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Raju V.K | last post by:
can I use javascript and PHP in the following manner to create a pop-up window: <--- in <head> </head> <script language=javascript> function popup(folder1, file1) {...
6
by: Johan Louwers | last post by:
I have a qustion. I have to set a JAVA_HOME variable on a Solaris9 system... what kind of a variable? A system-defined.../....a user defined.../.....???? and how do I set this so java can...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
15
by: Frances | last post by:
<html> <head> <script> function doIt() { var list = document.forms.product; var selItem = list.options.value; ^^^^^^^ </head>
5
by: Paul | last post by:
Just wondering if someone could provide an example of passing a variable from the code behind to javascript in vb. I want to have one control have focus with the page loading with one condition...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
2
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would...
1
satterfieldben
by: satterfieldben | last post by:
I have a newbie question about passing variables between functions. I am wanting to use a drop down box to select a value. Then base on which was selected, it would create a variable and I would call...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.