Click to See Complete Forum and Search --> : attaching onScroll event handler to the body


Tage
06-11-2004, 02:29 AM
Is it possible to attach an onScroll event handler to the body with a function using attachEvent()? I am well aware that this is not good to use if you are doing a professional website (and that it only works in Internet Explorer, I think). I am just curious! The best I could come up with was this, but it doesn't use attachEvent() from inside a function.<body onload="this.attachEvent('onscroll',alert)">I've tried<head>
<script type="text/javascript">
<!--
function doAttachEvent(what){
what.attachEvent("onscroll",alert)}
//-->
</script>
</head>
<body onload="doAttachEvent(this)">and this<head>
<script type="text/javascript">
<!--
function doAttachEvent(){
document.getElementById("theBody").attachEvent("onscroll",alert)}
//-->
</script>
</head>
<body id="theBody" onload="doAttachEvent()">and both FAIL. I thought the first would surely work. It doesn't, however. The second attempt was merely out of desperation, lol.

Tage

Tage
06-11-2004, 02:34 AM
Grarr, I JUST found the answer...<head>
<script type="text/javascript">
<!--
function doAttachEvent(){
window.attachEvent("onscroll",alert)}
//-->
</script>
</head>
<body onload="doAttachEvent()">Tage