pingeyeg
asked on
Function not working inside even listener script
I found a great listener script that listens for the onResize method, but I'm trying to pass another function inside this function that will update the document.title object and display the window's width. My problem is, I'm getting an undefined on my change() function. Any ideas?
function change() {
document.title = wWidth;
}
function attachEventHandler(element, eventToHandle, eventHandler) {
if(element.attachEvent) {
element.attachEvent(eventToHandle, eventHandler);
} else if(element.addEventListener) {
element.addEventListener(eventToHandle.replace("on", ""), eventHandler, false);
} else {
element[eventToHandle] = eventHandler;
}
}
attachEventHandler(window, "onresize", function() {
setTimeout("change()", 100);
if(wWidth > 1000) {
document.body.style.overflowY = "hidden";
} else if(wWidth <= 1000) {
document.body.style.overflowY = "scroll";
}
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
outside (and before) every function. This will make the variable "global"
http://www.webdevelopersnotes.com/tutorials/javascript/global_local_variables_scope_javascript.php3