Redirect a page with javascript when opening a new tab

1

I need to redirect a page with javascript after submitting a form, the problem is that this form opens in a new tab and after opening this new tab I need to redirect the original tab to a new address.

Using the code below I can not do this:

$("#gerarBoletoForm").on('submit', function(){
    window.location.replace('https://www.site.com.br/');
});

Not even if I use location.href or location.assign.

Is there any way to do this?

    
asked by anonymous 27.09.2016 / 15:14

2 answers

1

Based on the information you gave me, I was able to solve the problem.

First I set the target of my form in a new window created by me (not the form _target) after that I opened this new window and assign it to a variable and then submit the form.

After that I can use opener.location.href without any problems. Below is the solution code:

$("#gerarBoletoForm").on('click', function(){
    document.gerarBoletoForm.target = "novaJanela";
    var boletoWindow = window.open("","novaJanela","toolbar=0");
    document.gerarBoletoForm.submit();

    boletoWindow.opener.location.href = "https://www.site.com.br/";
});

From this it was possible to redirect the "mother window" without problems. Thanks for everyone's help!

PS: I do not know if it is the best solution but it was possible to solve it that way.

    
27.09.2016 / 16:01
1

The object window.opener gives you access to the "parent" tab. With window.opener.location.href you will be able to control your url.

    
27.09.2016 / 15:21