0

I have a login button with onclick event...onclick = "login();"

I successfully logged in ...but I wanted to open new tab instead.

This is my javascript:

login = function() {

    if ($("#UserName").val().length == 0) {
        return;
    }
    if ($("#Password").val().length == 0) {
        return;
    }
    var logindata = new Object();
    logindata.UserName = $("#UserName").val();
    logindata.Password = $("#Password").val();

    locustraxx.showLoading("loginformDiv");

    locustraxx.doAjaxPostback('//example.com/LoginHandler.ashx', logindata, null, null,
        function(data, textStatus, jqXHR) {

            var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);

            if (data.success == true) {
                if ($("#Remember").is(':checked')) {
                    $.cookie('remember', $("#UserName").val() + '|' + $("#Password").val(), {
                        expires: 36500,
                        path: '/'
                    });
                }
                var retUrl = $.QueryString("ReturnUrl");
                if (retUrl == undefined || retUrl == null) {
                    window.location.replace(data.data, '_blank');
                } else {
                    window.location.href = decodeURIComponent(retUrl).replace(/\~~/g, ".");
                }

                if (isChrome) {
                    // clearCookies();
                }

                return false;
            } else {
                alert(data.message);
                $("#UserName").focus();
            }
        }, null,
        function() {
            login.hideLoading("loginformDiv");
        });

}

I tried _blank... window open, but to no avail

Anas Mansuri
  • 159
  • 1
  • 2
  • 13
porsche
  • 55
  • 7

1 Answers1

0

Could you please specify better what you have tried so far in theory you should be OK with:

window.open('https://www.google.com', '_blank');

If It isn’t working please specify the error output of the console.

There is also a known issue in which the browser opens a new window instead of a new tab, but that has to do with the user preferences, nothing to do about that. See here.

Arch
  • 109
  • 11
  • And you can also check out the definition and usage of window.open() https://www.lifewire.com/open-link-new-window-javascript-3468859 – Arch Jun 19 '19 at 10:14
  • I tried to change window.location.replace(data.data, '_blank'); with window.open(data.data, '_blank'); but it doesn't work :( – porsche Jun 20 '19 at 06:20