Nygaming Posted June 22, 2017 Share Posted June 22, 2017 Hi, I'm licensing a game, but the publisher tells me that when they press the up or down keys the page scrolls. Here's a link to the game on my website, press the arrow keys and see if it scrolls happens, also if it does, click inside the game window and see if it stops. I've been told to put this code in the bottom of my index.html file, but it doesn't seem to work. <script> window.addEventListener("keydown", function(e) { // space and arrow keys if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) { e.preventDefault(); } }, false); </script> http://www.retroboltgames.com/copy-of-ihe-mars-attack Thanks! Quote Link to comment Share on other sites More sharing options...
Antriel Posted June 22, 2017 Share Posted June 22, 2017 It does scroll, it stops when the game is active. I would say that's expected behavior, but I suppose such script could fix that if desired. That script doesn't work though, because it's in the index of your game, which is inserted via `iframe`. The `window` is the iframe, not the whole page. You might be able to use `window.parent` but I think that won't work either unless the iframe is loaded from the same domain as the parent. Basically, the script needs to be included on the retroboltgames html file, not the game's index.html file. Quote Link to comment Share on other sites More sharing options...
Nygaming Posted June 22, 2017 Author Share Posted June 22, 2017 Ok, so instead of "window.addEventListener", `window.parent` might work. But to truly solve the problem, the publisher would need that script in their website's html file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.