faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 13 people (85%) answered Yes
Recently 5 of 7 people (71%) answered Yes

Entry

Why is the background color of my layers changing when resizing the window in NN4 ?

May 16th, 2000 07:46
Mike Hall, Delia Banc, http://www.webreference.com/dhtml/diner/resize/


NN4 is known to have bug that causes it to lose style definitions when 
the browser window is resized. The simplest way to correct this is to 
capture the resize event and reload the page.
This may expose another bug however. In early releases of NN4 the resize 
event fires as the page loads. This causes the browser to go into a 
loop, repeatedly reloading the current page.
To avoid this, you can check the browser dimensions when the page first 
loads. Then when a resize occurs, compare these values to the current 
window dimensions. If there is no change, the resize is not a true 
resize so you exit the handler. If they differ, the resize event is a 
true one and you can reload the page.
The code below can be added to a page to do just that.
<script language="JavaScript">
var origWidth;
var origHeight;
// Get current window size and set up resize handling.
if (document.layers) {
  origWidth  = window.innerWidth;
  origHeight = window.innerHeight;
  window.onresize = resizeFix;
}
function resizeFix() {
  // If window size has not actually changed, exit.
  if (document.layers &&
      origWidth == window.innerWidth &&
      origHeight == window.innerHeight)
    return;
  // Otherwise, reload the current URL.
  else
    window.location.href = window.location.href;
}
</script>