javascript - parent.alert event not getting fire on pressing enter key -
i have main jsp page in alert functionality modified using
window.alert=function(txt)
in other jsp pages loaded in same document using iframe. parent.alert used in of these pages keep consistency.
this piece of code working with
<div onkeypress="handlekey()"> <button id='done' onclick="example()" >submit</button> </div>
script portion following
<script> function handlekey(){ if ((window.event) && (window.event.keycode == 13)) { // click search button done.click(); } } function example(){ parent.alert('done'); } </script>
alert not fired if press enter key fired when click on button. alert gets fired when replace parent.alert alert.
this works fine me:
index.html
<html> <head> <script> window.alert = function(){ console.log('my alert'); } </script> </head> <body> <iframe src="iframe.html" id="myiframe"/> </body> </html>
iframe.html
<html> <head> <script> function handleevent() { if ((window.event) && ((window.event.keycode == 13) || window.event.type == 'click')) { example(); } } function example(){ parent.alert(); } </script> </head> <body> <div onkeypress="handleevent()"> <button id='done' onclick="handleevent()" >submit</button> </div> </body> </html>
Comments
Post a Comment