www.webdeveloper.com
Results 1 to 9 of 9

Thread: works in FF but not in Chromium

  1. #1
    Join Date
    Jul 2010
    Posts
    15

    works in FF but not in Chromium

    i have this script (and more but the problem is in these piece of code, i think)

    So, in FF i have a image and it moves with arrow keys. But in Chromium, the image is static, the action of the buttons is null, nothing happens

    any help?

    Code:
    function desenhaBonecoBx(){
        clear();
        context2D.drawImage(bonecoBottom, x, y);
        y += 10 * yDirection;
    }
    
    
    
    //mover boneco
    function moverBoneco(dir){
        if (dir == "esquerda") {
            desenhaBonecoDir();
        }
        if (dir == "direita") {
            desenhaBonecoEsq();
        }
        if (dir == "cima") {
            desenhaBonecoCim();
        }
        if (dir == "baixo") {
            desenhaBonecoBx();
        }
    }
    
    //teclas
    function teclar(evt){
        if (evt.keyCode == 38) {
            moverBoneco('cima')
        }
        if (evt.keyCode == 40) {
            moverBoneco('baixo')
        }
        if (evt.keyCode == 37) {
            moverBoneco('esquerda')
        }
        if (evt.keyCode == 39) {
            moverBoneco('direita')
        }
    }
    
    window.addEventListener('keypress', teclar, true)
    Last edited by fel; 03-08-2011 at 11:46 AM.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    capturing the keycode with onkeypress is inconsistent along the browsers. have you tried onkeydown?

    See also:
    http://www.quirksmode.org/js/keys.html
    http://www.quirksmode.org/dom/events/keys.html

    I hope you know that you are coding in HTML5, which is not well implemented in all the browsers, so far. Have you used the HTML5 syntax?

  3. #3
    Join Date
    Jul 2010
    Posts
    15
    thanks

    the question is. I test in FF, and if i use keypress, the image move when i have the key pressed, however, in chromium, if i use keypress, nothing happen, but if i use keydown it works in chromium like a keypress

    a bit strange
    Last edited by fel; 03-08-2011 at 12:46 PM.

  4. #4
    Join Date
    Dec 2005
    Posts
    2,984
    It's very important to check out the links that Kor posted as well - there's a bunch on inconsistencies between browsers with what key registers what code after being called with one event versus another.

    Checking out those links will show you a table which will clarify it all.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by fel View Post
    thanks

    the question is. I test in FF, and if i use keypress, the image move when i have the key pressed, however, in chromium, if i use keypress, nothing happen, but if i use keydown it works in chromium like a keypress

    a bit strange
    Can you post a full code (HTML included), please? Or a link to a test page? HTML code is important in relationship with the JavaScript code.

    And. once again: do you know that you try an HTML5 feature? Do you know something about the history of HTML, XHTML, JavaScript and all the cross-browser's problems all these years so far?
    Last edited by Kor; 03-08-2011 at 01:45 PM.

  6. #6
    Join Date
    Jul 2010
    Posts
    15
    at the moment i don't have any server, and it is much code to post (more than 500lines and 4 files ).

    I used the keydown, and it is solved more or less

    Yes i know that is html5, and i have some knowledge about programming. Yes it is true, the interoperability in the differents browsers are a big problem for all developers

    thanks one more time

  7. #7
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You could attach the files. Or you could isolate the representative HTML part of the code and post it (but, most of the time the full picture is important - some unexpected small errors in one of the part of the code can spoil something it it opposite part of it )

    It is hard for us to reproduce the error, if we have not enough information. Merely when it comes about cross-browser issues.
    Last edited by Kor; 03-08-2011 at 02:10 PM.

  8. #8
    Join Date
    Dec 2010
    Posts
    207
    My tests indicate that Chrome does not fire a keypress event for the cursor keys.


    Q: I found this code...
    A: Then find its author.

  9. #9
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by clueful View Post
    My tests indicate that Chrome does not fire a keypress event for the cursor keys.
    That brings us to my first presumption: onkeypress event is inconsistent. So: what about onkeydown?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles