rkayd 0 Light Poster

(I know this is the wrong forum to ask this but I haven't got any help on any of the Javascript forums I've asked this on so maybe someone here can help - or you can go to the Javascript section and answer it there if you like.)

I'm new to javascript and need to know how to store variables in cookies so that I can later use them later in php code.

Here is the basic javascript I want to use:

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );

Now, I want to save myWidth and myHeight in a cookie(s) but I don't know how to. The window.alert() will only be for testing purposes and will not be needed in the final code. I also need to know if the codes need to be in certain sections such as <head>, etc. Do I need to change any lines of code or need to add anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.