473,383 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 3455
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.