Skip to content Skip to sidebar Skip to footer

How To Make Multiple Url Opener In Html And Javascript

I am making a multiple url opener too in HTML and Javascript. I am getting some problems that HTTP links are opening but HTTPS links are not. Can anyone help me with that? Here is

Solution 1:

The issue is because your current code will add http:// to the start of any URL which starts with https://. You need to change your logic so that it checks for https:// at the start of the URL as well as http://. You can also tidy up the logic slightly and use trim() to ensure the line wasn't only whitespace. Try this:

functionopen_all() {
    var urls = document.getElementById("list_urls").value.split('\n');
    for (var i = 0; i < urls.length; i++) {
        var url = urls[i];
        if (url.trim()) {
            if (s.substr(0,7) != 'http://' && s.substr(0,8) != 'https://') 
                url = 'http://' + url;
            window.open(url);
        }
    }
    returnfalse;
}

Also note that you may have issues with your browser's popup blocker stopping you spamming the creation of so many windows so quickly.

Solution 2:

You have to add logic in your if condition for https-

if(s.substr(0,7)!='http://' && s.substr(0,7)!='https:/')

:)

Solution 3:

try this

functionopen_all() {
        debugger;
        var urls = document.getElementById("list_urls").value;
        var urls = urls.split('\n');
        var totalno = urls.length;
        var s;
        for (var i = 0; i < totalno; i++) {
            s = urls[i];
            if (s) {
                if (s.substr(0, 7) != 'http://' && s.substr(0, 8) != 'https://')
                    s = 'http://' + s;
                window.open(s);
            }
        }
        returnfalse;
    }

Post a Comment for "How To Make Multiple Url Opener In Html And Javascript"