Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

javascript - onKeyPress event not working in Firefox -


i have following javascript code...here using onkeypress="somefunction( )" in body tag keycode of key pressed.

the code working fine in ie8 not working in firefox.

please give solution this.

<html> <head> <title>onkeypress( ) event not working in firefox..</title> <script> function printdiv() {   var divtoprint=document.getelementbyid('prnt');   newwin=window.open(''+self.location,'printwin','left=50,top=20,width=590,height=840,toolbar=1,resizable=1,scrollbars=yes');   newwin.document.write(divtoprint.outerhtml);   newwin.print();   //newwin.close(); } </script>  <script> function keypress() {   alert(event.keycode);   var key=event.keycode;   if(key==112 || key==80)  printdiv();   else if(key==101 || key==69)     window.location="http://google.com";   else if(key==114 || key==82)     window.reset();   } </script> </head> <body bgcolor="lightblue" onkeypress="keypress()"> 

thanks in advance.....


here total code working fine in ie8 , not working in firefox.

<!doctype html> <html>     <head>     <title>please me out</title>     <script type="text/javascript">     function printdiv()     {       var divtoprint=document.getelementbyid('prnt');       newwin=window.open(''+self.location,'printwin','left=50,top=20,width=590,height=840,toolbar=1,resizable=1,scrollbars=yes');       newwin.document.write(divtoprint.outerhtml);       newwin.print();     }     </script>      <script type="text/javascript">     function keypress(val)     {       //-----------------------------------------------------          //alert('nnnn');       //alert(window.event ? event.keycode : val.which);         //if(val.which != 0 && val.charcode != 0)       // alert('firefox'+string.fromcharcode(val.which));       //else       // alert('ie');        //-------------------------------------------------------        var key=event.keycode;       if(key==112 || key==80 || val=="print")         printdiv();       else if(key==101 || key==69 || val=="exit")         window.location="http://google.co.in";       else if(key==114 || key==82 || val=="refresh")         document.forms[0].reset();         else         event.returnvalue=true;     }     </script> </head> <body bgcolor="lightblue" topmargin="0" leftmargin="0"marginwidth="0px" marginheight="0px" onkeypress="keypress(null)"> <table align="left" border="1" cellpadding="5" cellspacing="0" style="width: 100%;height:100%"> <tbody> <tr><td width="20%" valign="top">ccccccccccc</td>     <td width="80%" align="center">         <table style="width: 100%" border="0" valign="top">         <tr align="right">         <td valign="top">         <button value="refresh" accesskey="r" onclick="keypress(this.value)">             <b><u>r</u></b>efresh         </button>         <button value="print" accesskey="p" onclick="keypress(this.value)">             &nbsp;&nbsp;<b><u>p</u></b>rint&nbsp;&nbsp;         </button>         <button value="exit" accesskey="e" onclick="keypress(this.value)">             &nbsp;&nbsp;&nbsp;<b><u>e</u></b>xit&nbsp;&nbsp;&nbsp;         </button>         </td></tr>         </table>          <h3>press letters p->print , e->exit etc....</h3>            <h1>just test keypress event</h1>         <form action="http://google.co.in" method="post">             <div id="prnt">                 zzzzzzzzzzzzzzz             </div>         </form>     </td> </tr> </tbody> </table></body></html> 

when problems show up, start use kind of javascript framework. frameworks build avoid problems different browsers.

to catch different keypress() apis, link emmett shows, can difficult.

example:

in html head:

<script src="http://code.jquery.com/jquery-1.4.4.js"></script> 

in js tag:

$(document).keydown(function(event) {  alert('you pressed '+event.keycode);  event.preventdefault(); }); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -