Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

Using Javascript with HTA

$
0
0

I would like to know if I am able to use plain JavaScript with HTML applications. I have tried making a simple application, but I get an error when opening the HTA document. The error states "Object does not support property or method 'addEventListener'". My question is if JavaScript methods and functions ("addEventListener" for example) can be used within HTA documents.

I have posted all of the code below:

<!DOCTYPE html>
<html>
    <head>
        <title>hta game</title>
        <HTA:APPLICATION 
            applicationname="game" 
            border="no" 
            singleinstance="yes" 
            scroll="no"
        />
        <style>
            body {
                margin: 0;
                padding: 5px;
            }

            .ga {
                width: 845px;
                height: 623px;
                border: 2px dashed blueviolet;
                background: black;
            }

            .plyr {
                position: absolute;
                width: 50px;
                height: 50px;
                margin-left: 1px;
                top: 579px;
                background: blue;
            }
        </style>
    </head>
    <body>
        <div id="gameArea" class="ga">
            <div id="player" class="plyr"></div>
        </div>
    </body>
    <script language="javascript" type="text/javascript">
        window.onload = (function main(){
            window.resizeTo(880, 680);

            (function game(){
                setup();
            })();

            function setup(){
                (function playerFunctions(){
                    function moveControls(){
                        window.addEventListener('keydown', function(event) {
                            switch (event.keyCode) {
                            case 37: // Left
                                player.offsetLeft = 20 + "px";
                            break;

                            case 38: // Up
                                player.offsetHeight = 20 + "px";
                            break;

                            case 39: // Right
                                player.offsetLeft = -20 + "px";
                            break;

                            case 40: // Down
                                player.offsetHeight = -20 + "px";
                            break;
                            }
                        }, false);
                    }moveControls();
                })();
            }
        })();
    </script>
</html>

Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>