php html browser size

Discussion in 'HTML & Website Design' started by Silver89, Sep 24, 2007.

  1. #1
    Heres the problem,

    I have an

    if{}

    that currently works out if the embed size is over 900 then show the maximum width,

    but the maximum it cant be over is in pixels, but the maximum embed size is in %

    So i need to know how you can find out how big the current browser is, so how many pixels 100% would be,

    For example

    100% width = How many pixels

    100% hieght = How many pixels?

    Thanks
     
    Silver89, Sep 24, 2007 IP
  2. MetaCipher

    MetaCipher Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I am guessing you want to know the document width and height (essentially, the width and height of the display area). You can do this in JavaScript:

    
    XDocument = {};
    
    //=============================================================================
    XDocument.GetWidth = function() {
    	var Width = 0;
    
    	if(typeof(window.innerWidth) == 'number') {
    		//Non-IE
    		Width = window.innerWidth;
    	}else if(document.documentElement && document.documentElement.clientWidth) {
    		//IE 6+ in 'standards compliant mode'
    		Width = document.documentElement.clientWidth;
    	}else if(document.body && document.body.clientWidth) {
    		//IE 4 compatible
    		Width = document.body.clientWidth;
    	}
    
    	return Width;
    }
    
    //-----------------------------------------------------------------------------
    XDocument.GetHeight = function() {
    	var Height = 0;
    
    	if(typeof(window.innerWidth) == 'number') {
    		//Non-IE
    		Height = window.innerHeight;
    	}else if( document.documentElement && document.documentElement.clientHeight) {
    		//IE 6+ in 'standards compliant mode'
    		Height = document.documentElement.clientHeight;
    	}else if( document.body && document.body.clientHeight) {
    		//IE 4 compatible
    		Height = document.body.clientHeight;
    	}
    
    	return Height;
    }
    
    Code (markup):
    You cannot do this in PHP, as PHP has no idea how the browser will render anything.
     
    MetaCipher, Sep 26, 2007 IP
  3. Sparky1

    Sparky1 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Even though this is not my question, thanks! I had no idea.

    Cheers,
    Sparky
     
    Sparky1, Sep 26, 2007 IP
  4. James WP

    James WP Active Member

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    If you really want to use the information in your PHP, this may be one way of coding it, though perhaps not a search engine (or indeed user!) friendly solution:


    If the requested URL does not contain argument values for "width" and "height":

    - Serve a brief page containing JavaScript that will:
    -- Sense the browser proportions and save them to variables;
    -- Redirect to itself, appending these variables to the URL.

    If the requested URL does contain argument values for "width" and "height":

    - Use "GET" to retrieve these browser details, and serve the real page.
     
    James WP, Sep 26, 2007 IP