Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:55:13+00:00 2026-06-03T02:55:13+00:00

I am trying to get the Browser Viewport bay passing a Javascript Variable to

  • 0

I am trying to get the Browser Viewport bay passing a Javascript Variable to PHP with the following code:

First Code

<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
  // output the geometry variables
  echo "Screen width is: ". $_GET['width'] ."<br />\n";
  echo "Screen height is: ". $_GET['height'] ."<br />\n";
} else {
  // pass the geometry variables
  // (preserve the original query string
  //   -- post variables will need to handled differently)

  echo "<script language='javascript'>\n";
  echo "  location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
            . "&width=\" + screen.width + \"&height=\" + screen.height;\n";
  echo "</script>\n";
  exit();
}
?>

The above code gives me the Screen Width and the Height and this works fine in all browsers including IE6, 7 and 8 too.

But the moment I change it to from screen.width to window.innerWidth and screen.height to window.innerHeight

like this . "&width=\" + window.innerWidth + \"&height=\" + window.innerHeight;\n";

It works fine in all browsers but for IE6, 7 and 8 it says

Screen width is: undefined
Screen height is: undefined

While surfing the net for solutions I found another piece of code:

Second Code

<script type="text/javascript">
var w=window,d=document,e=d.documentElement,g=d.getElementsByTagName('body')[0],x=w.innerWidth||e.clientWidth||g.clientWidth,y=w.innerHeight||e.clientHeight||g.clientHeight;

document.write('<p>Your viewport size is '+x+' x '+y+'</p>');
</script>

This code displays the Browser Viewport and it works fine in all browsers including IE6, 7 and 8 too.

When I run both the codes together in a php file the first one shows as undefined abd the second one works perfectly. Please see the screenshots below

I am not a newbie programmer and not able to connect the second code to the first logic. Kindly help me do so.

Here are the screen shots of all browsers:

Internet Explorer 6

Internet Explorer 6

Internet Explorer 7

Internet Explorer 7

Internet Explorer 8

Internet Explorer 8

Internet Explorer 9

Internet Explorer 9

Forefox

Forefox

Google Chrome

Google Chrome

Opera

Opera

Safari

Safari

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:55:14+00:00Added an answer on June 3, 2026 at 2:55 am

    window.innerHeight/Width are not supported by IE8 and lower. Try using document.documentElement.clientHeight/document.documentElement.clientWidth

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the browser to redirect whenever the user types in /index.php
I am trying to get my search values from the android browser with following
i am trying to get the new browser width after resizing. i have tried
I'm trying to get the current browser viewport height, using $(window).on('resize',function() { console.log(new height
I'm trying to get the browser function in my Android application to work but
I am trying to get out of browser support working for my Silverlight application
I'm trying to get the onreadystate value from the browser control do detect when
well iam trying to get version of IE used by user by using $.browser.version
Trying to get comfortable with jQuery and I have encountered some sample code that
I am trying to determine the actual viewPORT size of the current browser window.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.