jquery conversion onclick to onload

1150 views javascript
5

I am a newbie and I have one website link which currently is working on clicking the link a window pop-up. but I want the onclick to happen automatically without clicking. maybe the onclick should work like onload but I am an absolute newbie at it. I tried a lot of google and StackOverflow search.. but I couldn't find the exact solution to my problem.

here's my code below

<!DOCTYPE html>
<html>
<head>
    <title>mygame | Browser</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="../api.js"></script>
    <script type="text/javascript">
        function initialize() {
            document.getElementById('robrowser').addEventListener("click", function(){
                var ROConfig = {
                    type:          ROBrowser.TYPE.POPUP,
                    application:   ROBrowser.APP.ONLINE,
                    remoteClient:  "http://play.mygame.com/client",
                    width:          1024,
                    height:         768,
                    development:    false,
                    servers: [{
                        display:     "mygame",
                        desc:        "mygame Revolution",
                        address:     "94.99.190.98",
                        port:        6900,
                        version:     46,
                        langtype:    12,
                        packetver:   20170614,
                        packetKeys:  false,
                        socketProxy: "ws://196.66.646.179:5999/"
                    }],
                    saveFiles:       true,
                    skipServerList:  true,
                    skipIntro:       true,
                    version:         1,
                    plugins: {
                        IntroMessage:  {}
                    }
                };
                var RO = new ROBrowser(ROConfig);
                RO.start();
            }, false );
        }
        window.addEventListener("load", initialize, false);
    </script>
</head>
<body>
    <input type="button" value="Run roBrowser" id="robrowser"/>
</body>

answered question

So why not just remove the event listener and execute the source code within the event listener inside your initialize() function?

how can I do it, sir? removing the event listener and execute the source code within the event listener ? can you please rewrite it for me, I am a newbie at it.

It should be as simple as removing the following lines of soce document.getElementById('robrowser').addEventListener("click‌​", function(){ and }, false ); Try that and let me know the results. Here is a PasteBin of the changes I have suggested.

2 Answers

7

<!DOCTYPE html>
<html>
<head>
    <title>mygame | Browser</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="../api.js"></script>
    <script type="text/javascript">
        function initialize() {

                var ROConfig = {
                    type:          ROBrowser.TYPE.POPUP,
                    application:   ROBrowser.APP.ONLINE,
                    remoteClient:  "http://play.mygame.com/client",
                    width:          1024,
                    height:         768,
                    development:    false,
                    servers: [{
                        display:     "mygame",
                        desc:        "mygame Revolution",
                        address:     "94.99.190.98",
                        port:        6900,
                        version:     46,
                        langtype:    12,
                        packetver:   20170614,
                        packetKeys:  false,
                        socketProxy: "ws://196.66.646.179:5999/"
                    }],
                    saveFiles:       true,
                    skipServerList:  true,
                    skipIntro:       true,
                    version:         1,
                    plugins: {
                        IntroMessage:  {}
                    }
                };
                var RO = new ROBrowser(ROConfig);
                RO.start();

        }
        window.addEventListener("load", initialize, false);
    </script>
</head>
<body>
    <input type="button" value="Run roBrowser" id="robrowser"/>
</body>

posted this
0

You can simulate a buttonclick like this:

$("#robrowser").click();

In this case you want to run the method when a page is loaded. You can just remove the entire onclick listener and call the function initialize() directly:

function initialize() {
                var ROConfig = {
                    type:          ROBrowser.TYPE.POPUP,
                    application:   ROBrowser.APP.ONLINE,
                    remoteClient:  "http://play.mygame.com/client",
                    width:          1024,
                    height:         768,
                    development:    false,
                    servers: [{
                        display:     "mygame",
                        desc:        "mygame Revolution",
                        address:     "94.99.190.98",
                        port:        6900,
                        version:     46,
                        langtype:    12,
                        packetver:   20170614,
                        packetKeys:  false,
                        socketProxy: "ws://196.66.646.179:5999/"
                    }],
                    saveFiles:       true,
                    skipServerList:  true,
                    skipIntro:       true,
                    version:         1,
                    plugins: {
                        IntroMessage:  {}
                    }
                };
                var RO = new ROBrowser(ROConfig);
                RO.start();
        }

initialize();

posted this

Have an answer?

JD

Please login first before posting an answer.