Javascript detecting iframe vertical scroll position

Trying to detect that someone has scrolled to the bottom of the iframe and "legally" read the text... Parent document has a form (splash) and an input field (legal) with original value of 0.

<script language="JavaScript">
var position = 0;

function startPolling(){setInterval("poll()",500)}

function poll(){
if (navigator.appName == "Microsoft Internet Explorer"){var position = document.body.scrollTop;}
else {var position = window.pageYOffset;}

if (position > 150)
{
      parent.document.splash.legal.value='1';
}

return true;

}
</script>
</head>

<body onLoad="startPolling()">

This is where the long text is...

</body>
</head>

It's not setting the value :( Any ideas what's wrong?
djrubinAsked:
Who is Participating?
 
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0
 
smaccariCommented:
Your function works for me (i put an alert instead of modifying an input's value) - test made with IE6.
0
 
djrubinAuthor Commented:
Nice to know I did that right, but why doesn't my value show any change in the parent script nor on its submission.... hmmm...

Here's the code on the parent...

<body bgcolor="#ffffff">
<cfform name="splash" id="splash" action="index.ep" method="post">
<table align="left" border="0" cellpadding="0" cellspacing="0" width="784">
              <tr>
               <td><img name="splash_r3_c1" src="images/splash_r3_c1.gif" width="104" height="153" border="0" alt=""></td>
               <td width="575" height="153" background="images/splash_r3_c2.gif">
                        <iframe src="disclaimer.ep" name="BottomFrame" width="100%" scrolling="auto" id="BottomFrame" allowtransparency="true">
                              Your browser does not support iframes.
                        </iframe>         
                  </td>
               <td><img name="splash_r3_c8" src="images/splash_r3_c8.gif" width="105" height="153" border="0" alt=""></td>
              </tr>
            </table>

      <cfinput type="text" name="legal" value="0">
</cfform>
</body>

Did I do something wrong on "top"?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
smaccariCommented:
Do you have an error, or is it just doing nothing?
If you place an alert in your function, do you see it pop?:

function startPolling(){setInterval("poll()",500)}

function poll(){
if (navigator.appName == "Microsoft Internet Explorer"){var position = document.body.scrollTop;}
else {var position = window.pageYOffset;}

if (position > 150)
{
   alert("foo");  
   parent.document.splash.legal.value='1';
}

return true;

}
0
 
djrubinAuthor Commented:
Firefox it works fine... IE nothing. I put in the alert and see it in FF (thanks for the endless loop of pop ups :) I added a detecting IF so that it appears once). Nothing in IE, no popup and no value changing... is there something wrong with the IE detection part of the code?
0
 
djrubinAuthor Commented:
Well here's the answer folks...

Needed to change the first line of the poll function to:

if (navigator.appName == "Microsoft Internet Explorer"){var position = document.documentElement.scrollTop;}

seems document.body.scrolltop is not good enough for IE so you have to reference it by documentElement

Now all works fine.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.