0

Hi I would like to make counter of written characters in my iframe and when I trying to trigger onkeydown or onkeyup event in iframe the function which is assigned to this events doesn't work.

Here is JavaScript code :

var maxAmount = 250;
 function textCounter(textField, showCountField){

    alert('abc');
    var numOfChars = textField.innerHTML.length;


    if(numOfChars > maxAmount){
        textField.innerHTML = textField.innerHTML.substring(0,maxAmount);
    }
    else{
        showCountField.value = maxAmount - numOfChars;
    }
 }

And here is my HTML code :

           <iframe name='richTextField' id='richTextField'
           onkeydown='alert("abc");'
           onclick='alert("abc");'
           <!--
           onkeydown='textCounter(this.form.richTextField,this.form.countDisplay);'
           onkeyup='textCounter(this.form.richTextField,this.form.countDisplay);'
           -->
          ></iframe>

          <input readonly type='text' name='countDisplay' size='3' maxlength='3'              
          value='250'>Character remaining

          <!-- End replacing your textarea -->
</form>

Before iframe element I have textarea element to pass what I will write in iframe to PHP script :

<form>
 <!--Hide (but keep) your normal textarea and place in the iFrame replacement for it -->
 <textarea name='myTextArea' id='myTextArea' cols='100' rows='14'></textarea>

But textarea has display:none css style to not interfere in iframe. I have placed there diagnosis alert('abc') functions but they doesn't work either.

Can anyone help with this problem ?

  • 3
    If this worked, you could easily steal passwords and sensitive data from other pages in an iframe. Is the iframe you are using of the same domain? – juvian Oct 21 '14 at 17:08
  • @ juvian - well said! – Manjunath Siddappa Oct 21 '14 at 17:09
  • I am just making a website on localhost by now but in future I am going to add this page on some domain :) I realy don't intent to steal any data from anyone. Just want to make small count character on this website. Anyone can help ? – Nanderedal Oct 21 '14 at 17:11
  • Well, as long as your parent page is on same domain as the iframe, it should be possible to do this. Maybe this helps: http://stackoverflow.com/questions/1654017/how-to-expose-iframes-dom-using-jquery – juvian Oct 21 '14 at 17:16

0 Answers0