Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to set "onInput" and "onpropertychange" listener on ifra

Status
Not open for further replies.

javascript123456

Technical User
Feb 18, 2011
4
0
0
HK
i am trying to make a comment editor with iframe, and want to trigger the change of content inside iframe, the following code cant work.

it is strange because it works fine when i replace them with "keypress" and "blur"

Code:
<iframe id="iframe"></iframe>

<script>

frameobj=document.getElementById('iframe').contentWindow; 

// IE
frameobj.attachEvent('onpropertychange', function(){alert();} );

//FireFox
frameobj.addEventListener('input', function(){alert();} , false);

</script>
 
You can't. iframes don't have oninput events because they can't receive input. Textreas, or textboxes within them can.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
i think not, u can tuen a iframe into edittable by following code

frameobj=document.getElementById('iframe').contentWindow;
frameobj.document.designMode="On";
frameobj.document.contentEditable = true;

<iframe id="iframe"></iframe>
 
Yes, you can make an iframe editable, but its still not an input element. Therefore it doesn't have an onInput event.

The closest you could get is perhaps using onKeyup or onblur to do something when they exit the iframe, or when they type into it.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top