Open link in a new tab without the target or window.open

8

I have a function that does a redirect:

vm.pagarUpload = function() {
    $http({
        method: 'POST',
        url: API.url + 'app/service.php?t=pagarUpload',
        data: {
            nome: vm.nomeUpload,
            email: vm.emailUpload,
            cpf: vm.cpfUpload
        }
    }).then(function successCallback(response) {
        console.log('redirecionando...');
        window.location.href = "https://minhaurl.com/payment.html?code=" + response.data;
    });
}
                    
asked by anonymous 18.12.2017 / 12:38

2 answers

5

With window.location will not be possible because it references only the same page. You can create a dynamic link in ajax return with target=_blank and click on it:

vm.pagarUpload = function() {
    $http({
        method: 'POST',
        url: API.url + 'app/service.php?t=pagarUpload',
        data: {
            nome: vm.nomeUpload,
            email: vm.emailUpload,
            cpf: vm.cpfUpload
        }
    }).then(function successCallback(response) {
        var link = document.createElement('a');
        link.href = "https://minhaurl.com/payment.html?code="+response.data;
        link.target = '_blank';
        document.body.appendChild(link);
        link.click();
        delete link;
    });
}
                                    
18.12.2017 / 12:51
0

You can do this using window.open even with a variable, and after the return of Ajax, redirect the contents of the open tab / window. This prevents the browser from blocking the popup.

In the link you enter window.open with a variable:

<a href="#" onclick="janela = window.open()">Abre nova aba/janela</a>

In Ajax you redirect the URL of janela :

janela.location.href = "https://minhaurl.com/payment.html?code=" + response.data;

EDIT

You can create a default% s page with the text "Opening ..." or "Redirecting ..." in the popup before Ajax returns, to inform the user that the page is being processed:

.html

    
18.12.2017 / 13:18