We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

DaveChild on 02/04/09


Tagged

javascript


Versions (?)


JavaScript Apply Max-Width (in Pixels) in IE


Published in: JavaScript 


URL: http://www.addedbytes.com

  1. var maxWidth = '750'; // Max width of area to be resized
  2. var content_area_id = ''; // ID of the element to be resized
  3.  
  4. var resizeTimeout = null;
  5.  
  6. function fixWidth() {
  7. var visibleArea = document.documentElement.clientWidth;
  8. if (visibleArea > maxWidth) {
  9. document.getElementById(content_area_id).style.width = maxWidth;
  10. } else {
  11. document.getElementById(content_area_id).style.width = visibleArea;
  12. }
  13. }
  14.  
  15. function addLoadEvent(func) {
  16. var oldonload = window.onload;
  17. if (typeof window.onload != 'function') {
  18. window.onload = func;
  19. } else {
  20. window.onload = function() {
  21. if (oldonload) {
  22. oldonload();
  23. }
  24. func();
  25. }
  26. }
  27. }
  28.  
  29. window.onresize=function(){
  30. if (resizeTimeout) {
  31. window.clearInterval(resizeTimeout);
  32. }
  33. resizeTimeout = setTimeout(fixWidth, 500);
  34. }
  35.  
  36. addLoadEvent(fixWidth);

Report this snippet 

You need to login to post a comment.