views:

122

answers:

1

Is there a way to check for scrollbars? What I need is a way to see if the user has written too much text in an iframe (using punyMCE). If the user has gone beyond the allowed number of lines (which will cause scrollbars to appear), I want to tell the user that the maximum number of lines has been entered.

Now there is a second problem. I can't seem to get key-events to fire from inside the punyMCE frame. Which means there is no way for me to do the check... Any suggestions? I tried this:

frame = frames['eventTxt_f'].document.getElementsByTagName('body')[0];
frame.onkeydown = function() {
    alert("keydown");
}
+1  A: 

A simpler way would probably be to compare the clientHeight of the contents of the iframe with the outer height of the iframe. Something like this:

if (window.frames[0].innerHeight < window.frames[0].document.documentElement.clientHeight)
    alert('too much!');

(tested quickly with the PunyMCE Simple Example with FF3)

kkyy
clientHeight seems to return 0 every time for me... using IE7
peirix
You have to use document.body.clientHeight instead of document.documentElement.clientHeight when the window/iframe is in Quirks Mode. But in general you don't ever want to be in Quirks Mode.
bobince