1 (edited by TheWHeel 2012-06-13 1:49:14 PM)

Topic: Retrieve browser window size how to?

I know it's possible to "read" the browser window width and height with Javascript.
Albeit, I'm not very good with java(script) (thats why I love XAJAX ;-) and I'm new to XAJAX .. so is there someone out there that can, and is willing to, help me with this?
Thanks in advance!

Re: Retrieve browser window size how to?

Hi,

Maybe something like this:

Php:
function receiveWinSize($w, $h){
  $resp = new xajaxResponse();
  <do something with the width and height>
 return $resp;
}

Javascript:

 function sendWinSize(){
   var w = window.innerwidth;
   var h = window.innerHeight;
   xajax_receiveWinSize(w,h);
}

Html:

<body onload="sendWinSize();">
...
If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Retrieve browser window size how to?

Thanks  EdRobinson for your prompt reply.

It looks simple enough but I cannot get it to work.

I allready have a onload function that I call:

== code snippit ====
<body onLoad="xajax_processForm('Start'); return false;">
<script type="text/javascript">
<!--
        function sendWinSize(){
            var w = window.innerwidth;
            var h = window.innerHeight;
            xajax_receiveWinSize(w,h);
        }
//-->
</script>
        <form name="my_form" id="my_form" method="post">
...
== end code snippet ==

My program is build with the following files from an example that I copied:

    - <test1.php>      // only html
    - <test1.css>       // the css
    - <test1.common.php>
    - <test1.server.php>

If I add the call to the body tag like this:

<body onLoad="sendWinSize(); xajax_processForm('Start'); return false;">

then both the sendWinSize() and the processForm() function's are not called (I don't see any output anymore...)

Can you please tell me how I can call the "sendWinSize()" function from a php function???

Thanks again!!!

4 (edited by TheWHeel 2011-09-18 7:21:04 PM)

Re: Retrieve browser window size how to?

Ok, found out how to do this!!!

Changed the javascript function into:

      function sendWinSize(){
            var w = getWidth();
            var h = getHeight();
            xajax_receiveWinSize(w,h);
            xajax_processForm('Start');
      }

.. and now it works .. sort off... I get the correct width and heigh values when load the page two times...

Anyway: thanks for the help.

XAJAX is really great!

Re: Retrieve browser window size how to?

OK, here's how to do both in one call:

<?php
/*
  9/18/11
  Do 2 xajax functions on start
*/  

include 'libs/xajax/xajax_core/xajax.inc.php';
$xajax = new xajax();
$xajax->configure('javascript URI','libs/xajax/');

function receiveWinSize($w, $h){
  $resp = new xajaxResponse();
  $resp->alert("Received $w, $h");
  $resp->loadCommands(Start());  
  return $resp;
}

function Start(){
  $resp = new xajaxResponse();
  $resp->alert("In function Start");
  return $resp;
}

$xajax->register(XAJAX_FUNCTION,'receiveWinSize');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<?php $xajax->printJavascript(); ?>
<script>
 function sendWinSize(){
   var w = window.innerWidth;
   var h = window.innerHeight;
   xajax_receiveWinSize(w,h);
}
</script>
</head>
<body onload="sendWinSize();">
</body>
</html>

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Retrieve browser window size how to?

Hoi Ed,

You're the best!!! See so many useful answers from you in @ this Forum!!

Changed my program-files as you suggested and YES!! it works!

Still have to figure out how-and-why tough! Not nearly enough knowledge of Javascript and certainly not enough of XAJAX!

Can't you write a book with examples??? I'd buy it instantly!!

Regards,

Willem

Re: Retrieve browser window size how to?

Thanks for the kind words Wiillem.

It works because the onload event calls the js  send WinSize which calls the xajax function receiveWinSize. That function calls your start function via the loadcommands function of the response object. loadcommands adds the response returned by start to its own commands.

In setting up things you call $xajax->processRequest(). This function intercepts the incoming XHR request, decodes it and calls your function passing it any parameters specified. Your function returns a response object to processRequest and it builds and sends the response back to the client. Best part is you didn't have to write any code for all of this to happen!

I am retiring soon and have been wondering what to do with the time. Maybe a book would be a good idea.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Retrieve browser window size how to?

Hi Ed,

How's the progress on your book about XAJAX???

Regards,

Willem

Re: Retrieve browser window size how to?

Hi Willem,

It's been pretty slow...

I have been working off and on on a HelpNDoc project about Xajax and it's comming along slow but sure.

Now that xajax 0.6 development is back on I hesitate to go too far with it.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Retrieve browser window size how to?

The great masterpiece with nice and informative post and topic that move me and enlarged my eyeline quite a lot.Thanks for sharing with us. I really favor in you!

11 (edited by lipkerson 2012-10-06 8:21:24 AM)

Re: Retrieve browser window size how to?

I tried to use code written by edrobinson but it does not work:
I recived appropriate data in function function receiveWinSize($w, $h) but when it goes to line:
$resp->loadCommands(Start()); 
it froze and don't go any further.
There in nothing in browser or in debug.

I have xajax 0.6 beta1. xajax work fine: examples from installation package do not show any errors.
What might i t be?
With regards !

Re: Retrieve browser window size how to?

Strange... Post your code unless it's a direct copy of mine.

Also check the apache error log.

I haven't tried this with 0.6

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Retrieve browser window size how to?

Found it!

in 0.6 the loadCommands has been replaced with:

appendResponse($mCommands, $bBefore=false)

Here's the revised code:

<?php
/*
  10/6/2012
  Do 2 xajax functions on start using xajax0.6
*/  

include 'xajax0.6beta/xajax_core/xajax.inc.php';
$xajax = new xajax();
$xajax->configure('javascript URI','xajax0.6beta/');

function receiveWinSize($w, $h){
  $resp = new xajaxResponse();
  $resp->alert("Received $w, $h");
  $resp->appendResponse(Start());  //<--changed for 0.6
  return $resp;
}

function Start(){
  $resp = new xajaxResponse();
  $resp->alert("In function Start");
  return $resp;
}

$xajax->register(XAJAX_FUNCTION,'receiveWinSize');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<?php $xajax->printJavascript(); ?>
<script>
 function sendWinSize(){
   var w = window.innerWidth;
   var h = window.innerHeight;
   xajax_receiveWinSize(w,h);
}
</script>
</head>
<body onload="sendWinSize();">
</body>
</html>

Guess I need to do more work with 0.6...

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Retrieve browser window size how to?

wow!!!