0

Hello fellow code people :)

I am a frontend web developer and as such in need of constant knowledge of the actual viewport size in order to see where in responsive designing breakpoints start and end. I know FF's own 'test window size' function, but came across a very handy extension: FireSizer. the extension has one itsy bitsy drawback: It gives back the window-size including FF's borders and scrollbar. I need the viewport-size though. So I need the extension hacked, but dont't know enough javaScript to do so. Maybe someone is willing to help em out here?

I would love the extension to actually look for the scrollbar, and subtract from the width a) 14 if no scrollbar present or b) 30 if scrollbar present

I found of what I think is the right place to alter the code:

//
// Update the status bar panel with the current window size
//
function FiresizerUpdateStatus() {
    var width  = window.outerWidth  + ''; // <- Think code needs to be edited here
    var height = window.outerHeight + '';
    document.getElementById("firesizer-statuspanel").label = width + 'x' + height;
}

Thanks for any effort! AO

@Chen Asraf: Well thank you very much. I didn't know there was an element to call the document-width. I changed the code to the following, and that did the trick (also when compared to FF's own 'Responsive Design View mode', which is spot on, its off by 2px - which i subtract from clientWidth.)

function FiresizerUpdateStatus() {
var width  = window.outerWidth  + ''; // changed this line to:
var width  = document.documentElement.clientWidth-2 + '';
var height = window.outerHeight + '';
document.getElementById("firesizer-statuspanel").label = width + 'M' + height;
}

Thanks AO

  • possible duplicate of [Detect if a page has a vertical scrollbar?](http://stackoverflow.com/questions/2146874/detect-if-a-page-has-a-vertical-scrollbar) – user123444555621 Aug 25 '13 at 14:21

1 Answers1

0

Possible duplicate of Get the browser viewport dimensions with JavaScript

Seems like you can get the window's inner dimensions by using:

// My window is maximized; screen is 1366x768

alert(document.documentElement.clientWidth);
// ^ returns 1349 (17 missing pixels because of scrollbar)

alert(document.documentElement.clientHeight);
// ^ returns 643 (125 pixels missing because of start bar & Chrome toolbars)

You can then compare the following with whatever else you need (for example, compare client width with window width to find if the difference is big enough to be a scrollbar - just experiment with the sizes)

Community
  • 1
  • 1
casraf
  • 21,085
  • 9
  • 56
  • 91