Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2007, 08:12 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default how to get browser's width via javascript

Hi,

i am completely new to java script, and want to add some java script code into my web page, there is a little problem with this.

Objective : how to get width of the browser

javscript file :
......
......
CONTAINER_WIDTH = document.getElementById("CONTAINER").style.width;
......

css :

#CONTAINER {
    overflow:hidden;
    height:1.4em;
    width:auto; /* works well in firefox not in IE*/
/* width:1000px i have to give value for IE */
}

problem : i am creating a floting web page, so i cannot give a fixed value of container's width, is there any method in javascript so that i can get the width of the browser and provide it to this variable so that my page design remains floting. i just want that, container just cover the whole window.

i have checked for this forum, but could not get this, and tried some screen.width and other function too, but did not get the solution

all suggestions are welcome,

thanks for hearing

regards,

ashok sharma


Reply With Quote
  #2 (permalink)  
Old March 31st, 2007, 07:34 AM
Registered User
 
Join Date: Mar 2007
Location: , , Netherlands.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is not originally mine, but also I don't know who originally wrote this. I use it to calulate heights, my widths are always 100% browser width. It calculates the browser's height and width. Hope that this helps:
Code:
viewport =
{
   getIECanvas: function ()
   {
      var canv = null;
      if (!window.opera && document.all && typeof document.body.clientWidth != "undefined")
      {
         var cm = document.compatMode && document.compatMode == "CSS1Compat";
         canv = cm ? document.documentElement : document.body;
      }
      return canv;
   },

   getWinWidth: function ()
   {
      var canv;
      if ( canv = this.getIECanvas() )
         this.width = canv.clientWidth;
      else
         this.width = window.innerWidth - 18;
   },

   getWinHeight: function ()
   {
      var canv;
      if (canv = this.getIECanvas())
         this.height = canv.clientHeight;
      else
         this.height = window.innerHeight - 18;
   },

   getScrollX: function ()
   {
      var canv;
      if (canv = this.getIECanvas())
         this.scrollX = canv.scrollLeft;
      else if (window.pageXOffset)
         this.scrollX = window.pageXOffset;
      else if (window.scrollX)
         this.scrollX = window.scrollX;
      else
         this.scrollX = 0;
   },

   getScrollY: function ()
   {
      var canv;
      if (canv = this.getIECanvas())
         this.scrollY = canv.scrollTop;
      else if (window.pageYOffset)
         this.scrollY = window.pageYOffset;
      else if (window.scrollY)
         this.scrollY = window.scrollY;
      else
         this.scrollY = 0;
   },

   getAll: function ()
   {
      this.getWinWidth();
      this.getWinHeight();
      this.getScrollX();
      this.getScrollY();
   }
};
So you'd get something like:
Code:
viewport.getWinWidth();
object.style.width = (viewport.width-200) + "px";
Thanks,Erik.
Reply With Quote
  #3 (permalink)  
Old April 2nd, 2007, 03:11 AM
Authorized User
 
Join Date: Feb 2006
Location: jaipur, rajasthan, India.
Posts: 67
Thanks: 7
Thanked 0 Times in 0 Posts
Send a message via Yahoo to beetle_jaipur
Default

Thanks Erik

it helped me a lot

thanks for your consideration

ashok sharma

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser's BACK Button Problem phungleon Classic ASP Databases 6 May 16th, 2005 03:10 PM
Disabling browser's "X" button farhanzia HTML Code Clinic 4 March 23rd, 2005 01:19 PM
Width in pixels from width in percentage bsausser Classic ASP Basics 1 December 31st, 2003 02:31 PM
Disabling browser's "X" button farhanzia Javascript 1 July 9th, 2003 10:04 AM



All times are GMT -4. The time now is 11:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.