set a variable without clicking or posting

set a variable without clicking or posting

I'm trying use this as a 404.shtml error page:


  1. <script src="http://code.jquery.com/jquery-latest.js"></script>
  2. <script language="javascript" type="text/javascript">
  3. var viewportwidth;
  4. var viewportheight;
  5. /* the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight */
  6. if (typeof window.innerWidth != 'undefined'){
  7. viewportwidth = window.innerWidth,
  8. viewportheight = window.innerHeight
  9. } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
  10. viewportwidth = document.documentElement.clientWidth,
  11. viewportheight = document.documentElement.clientHeight
  12. } else {
  13. viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
  14. viewportheight = document.getElementsByTagName('body')[0].clientHeight
  15. }
  16. $.post('404.php', { js: "viewportwidth"});
  17. </script>
and have this code in the 404.php page
  1. <?php
  2. session_start(); //start PHP Session
  3. $_SESSION['jsvalue'] = $_POST['js']; //store the posted value in a php session variable
  4. ?>
  5. This is a PHP Page. The javascript value is: <?php echo $_SESSION['jsvalue']; ?

How can I get it to call the php page without clicking or posting anything...
If I add after above code, th e virtual include " <!--#include file=" 404.php " -->" to the shml file so it doesn't mess with the request uri there is no var set.

I have tried a bunch of other jquery functions trying to get to work... I'm not a js, jquery or ajax wizard so please hold my hand...

Thanks in advance... I'm running out of hair... lol