Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How do I loop this to constantly check the browser size?

Featured Replies

Hey,

 

I am playing around with some javascript stuff in "Javascript the definitive guide" and I have this little piece of code :

 

 

<script>

 

function find_browser_size() {

var elt = document.getElementById('results_div');

 

var cords = elt.getBoundingClientRect();

 

 

 

var findWidth = cords.width;

var findHeight = cords.height;

 

 

document.write('the current width of the div is:' + findWidth + ' pixels wide.' +'<br/>');

 

document.write('the current height of the div is:' + findHeight + ' pixels high.');

 

}

 

find_browser_size();

 

 

 

</script>

 

All it is doing if finding the size of the window and outputting the result to the screen. If I resize the window and refresh, it updates but I want it to constantly check to see if the browser has been resized, so that the results change as soon as the window is resized.

 

How would I do this?

 

Many thanks for any help :)

Try this:

 

<html>
<style type="text/css" >
*
{
padding:0px;
margin:0px;
}
body , html
{
width:100%;
height:100%;
}

</style>
<body  onresize='resize()' >

<div id="holder" ></div>

<script type="text/javascript">
function resize()
{
var bodyWidth = window.getComputedStyle(document.body,null).getPropertyValue('width');
var bodyHeight = window.getComputedStyle(document.body,null).getPropertyValue('height');
document.getElementById('holder').innerHTML = 'Width: '+bodyWidth + ' Height: '+bodyHeight;
}
</script>
</body>
</html>

 

Notes:

Not tested in IE.

Dosen't work if body element is bigger then the height of the browser,

because it actually returns the height of the body element, and not the available height of your browser.

Better yet, don't mix Javascript with mark up. You should avoid this:

 

<body onresize='resize()' >

 

And stick to the following within the <script> tags:

 

window.onresize = resize;

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.