Skip to content

Instantly share code, notes, and snippets.

@dipakcg
Created December 1, 2016 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipakcg/3e34956e05e9ece6f52bed6e921e4818 to your computer and use it in GitHub Desktop.
Save dipakcg/3e34956e05e9ece6f52bed6e921e4818 to your computer and use it in GitHub Desktop.
Get browser window size using jQuery (useful for responsive web design)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get browser window size using jQuery (useful for responsive testing)</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(window).bind({
load:function(){
var windowSize = $(window).width();
$('p.window-width').text('Window width = ' + windowSize + 'px');
},
resize:function(){
var windowSize = $(window).width();
$('p.window-width').text('Window width = ' + windowSize + 'px');
},
});
</script>
</head>
<body>
<h1>Resize your browser window to get width:</h1>
<p class="window-width"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment