Get browser viewport


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <script src="http://code.jquery.com/jquery-git.js"></script>
  6.  
  7. <script>
  8. $(window).resize(function() {
  9. $("#test").text($(document).width() + " x " + $(document).height());
  10. });
  11. </script>
  12. </head>
  13. <body>
  14. <button id="getp">Get Paragraph Height</button>
  15. <button id="getd">Get Document Height</button>
  16. <button id="getw">Get Window Height</button>
  17.  
  18. <div>&nbsp;</div>
  19. <p>
  20. Resize window
  21. </p>
  22. <script>
  23. function showHeight(ele, h) {
  24. $("div").text("The height for the " + ele +
  25. " is " + h + "px.");
  26. }
  27. $("#getp").click(function () {
  28. showHeight("paragraph", $("p").height());
  29. });
  30. $("#getd").click(function () {
  31. showHeight("document", $(document).height());
  32. });
  33. $("#getw").click(function () {
  34. showHeight("window", $(window).height());
  35. });
  36.  
  37. </script>
  38. <div id="test"></div>
  39. </body>
  40. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.