Synook Posted September 15, 2007 Share Posted September 15, 2007 Edit: Oops - I fixed the problem (why does that always happen just after I post?)The set handler line should read document.onkeydown = function(e) {Hello all,I don't understand why the error message as in the title comes when I try to set a handler to document.onkeydown. The function is function welcome() { set_pause(true); pages = new Array( "Welcome to the JavaScript.RolePlayingGame, a new entirely JavaScript-based text-based role playing game for the FireFox web browser.", "This is the second page" ); current_page = 0; console.innerHTML = pages[current_page]; document.onkeydown = new function(e) { if (!e) e = window.event; var keycode = e.charCode ? e.charCode : e.keyCode; if (keycode == 38 && current_page != 0) { current_page--; } else if (keycode == 40) { if (current_page != pages.length) { current_page++; } else { set_pause(false); } } console.innerHTML = pages[current_page]; }} The complete code can be seen at http://www.roundeddesign.com/experiments/rpg.htm (only works in Firefox).I set the onkeydown handler before the function, as well, and want to overwrite it. Does this make a difference? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.