简体   繁体   中英

Javascript or jQuery. Launch multiple URLs pulled from input text

I wrote a basic function as follows:

        function launchIt() {
            var input = document.getElementById('webaddy'),
                webAddy = input.value;
            if (webAddy) {
                    // initialize array
                    var arr = new Array(6);
                    arr[0] = "/css/img/bg-home.jpg?reset=1";
                    arr[1] = "/css/img/bg-large.jpg?reset=1";
                    arr[2] = "/css/img/bg-medium.jpg?reset=1";
                    arr[3] = "/css/img/bg-small.jpg?reset=1";
                    arr[4] = "/css/img/bg-xlarge.jpg?reset=1";
                    arr[5] = "/css/img/bg-xsmall.jpg?reset=1";

                    // display all values
                    for (var i = 0; i < arr.length; i++) {
                        alert(webAddy + arr[i]);
                    };
            }
        }

It works. I get the web address from the webaddy input field's value. I want to change the alert() to something like window.open . I have tried window.open , but it only opens the first array item and then stops. Any suggestions?

It was my browser's built-in popup block! Thanks to @user1105047!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM