0

Is there a way to get the size of a browser's console using javascript?

I've tried looking at window.console but don't see anything there.

My need for this arises when I try to get the innerHeight of a browser in fullscreen mode. With the console closed, window.screen.availHeight - (window.outerHeight - window.innerHeight) works well, but when the console is open, the value (window.outerHeight - window.innerHeight) includes the top toolbar and the console. I would like to subtract the size of the console.

(I am aware the console can also go on the side but lets just talk in terms of height)

gstoll
  • 51
  • 5
  • Why not use jQuery? You can test resizing the console window, and open and close the console with this 1 sec interval: `setInterval(function() { console.log($(document).height()); }, 1000)` – Peter Thoeny Jan 20 '23 at 06:05
  • Currently on linkedIn learning learning about jQuery. Opening the console doesn't affect the height of the html document? – gstoll Jan 20 '23 at 06:22
  • AFAIK you can't get the size of the console. You can get the size of the window and the size of the body. If the console is opened in the window, you can calculate windows - body (what you're already doing in the question). But you can't get the size of a floating console. – jabaa Jan 20 '23 at 06:27
  • `$(document).height()` returns the height of the visible document area, e.g. shrinks and increases as you resize/open/close the console. – Peter Thoeny Jan 20 '23 at 06:30
  • I understand your first comment more now. I am trying to find the size programmatically. Is there a way to open and close the console with javascript or jquery? – gstoll Jan 20 '23 at 06:35
  • I am pretty sure you can't programmatically open and close the console, short of using Selenium – Peter Thoeny Jan 20 '23 at 06:49
  • Would be interesting to know your use-case for this. Are you tying to fill it up with a graphic or something? – freedomn-m Jan 20 '23 at 09:36
  • I'm trying to set `min-height`'s of my elements based on the fullscreen size, and I think I figured it out. If I set off a mouse event at (0,0) in the DOM I can use `MouseEvent.screenY` to calculate the size of the top toolbar – gstoll Jan 20 '23 at 19:35
  • TBH you should base your elements on the view port size, not the user's screen. If I open your page in a "normal" size window, eg 1920x1080 then your elements will be ridiculously and unusably huge as my monitor is substantially larger than 1920x1080 – freedomn-m Jan 21 '23 at 11:08
  • This probably answers your *actual problem* (XY question) : https://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window – freedomn-m Jan 21 '23 at 11:13
  • Also, if you consider window+toolbar+console heights, then it still won't be full screen height unless the user has the browser maximised (or otherwise matching the full height of the screen). Again, I *rarely* use maximised windows due to the size of the monitor. People with two(+) monitors also won't as with window will (or at least used to) span across both monitors which is unusable. – freedomn-m Jan 21 '23 at 11:17
  • This is just a personal project. I'm going to post an answer in this next week – gstoll Jan 23 '23 at 07:24

0 Answers0