javascript - Single keypress firing twice when controlling content in a second window -


the problem: i'm getting double keypresses 1 keypress event when event updates content in 2 windows. (i hobbyist. please forgive lack of expertise. thanks.)

i trying use 1 browser window control display of contents in window launched first window. first window has div shows content sent second window.

i'm using shortcut.js assign space bar command update each window. problem i'm describe occurs when use plain old jquery keypress() function. i've tried altering parameters of shortcut.js function no avail.

here's simplified version of code:

g_win = window.open('displaywin.html'); // launch second window slidecontent = updatethecontent(); // new content window #2 slidecontentpreview = alterthecontent(slidecontent); // modify window #1  if (g_win != undefined){ // window #2 open?     $("#display2").html(slidecontent);  // display content in window #2 } $("#display1").html(slidecontentpreview); // display content in window #1 

here's jquery keypress code:

$(document).keypress(function(e) { switch(e.which) {     case 32: {  // space         shownextslide();         break;     } default: return;  } e.preventdefault(); });      

the weird thing works fine if haven't launched second window. if g_win launched, content updated properly, space keypress event triggered again, causing program update contents again. effect every other piece of content skipped in both windows.

what amazingly obvious mistake making? thanks!

[later:] here entire html window #2:

<!doctype html>    <html lang="en">     <head>     <meta charset="utf-8" />     <title>whatev</title>     <link href='http://fonts.googleapis.com/css?family=special+elite' rel='stylesheet' type='text/css'>   <link href='http://fonts.googleapis.com/css?family=open+sans' rel='stylesheet' type='text/css'>   <link href='http://fonts.googleapis.com/css?family=droid+serif' rel='stylesheet' type='text/css'>     <!--link type="text/css" rel="stylesheet" href="css/displaywin.css"-->    </head>     <body>      <div id="container">    <div id="display2">         click in presenter view start     </div>      </div>     </body>     </html> 

my guess bind same keypress event handler second time when load second window, because loads same javascript. might solve issue setting handler when window 2 not yet loaded. along lines of:

if($("#display2").html() == ""){   $(document).keypress(function(e) {   switch(e.which) {     case 32: {  // space         shownextslide();         break;     }   default: return;    }   e.preventdefault();   }); } 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -