JavaScript buttons

0

I have a page with save button, but every time it is clicked the script appears that the information has been saved and exits the page. My goal is for him not to quit, but I looked at the code and I did not understand why he was leaving. Follow the button:

<div class="row">
        <div class="col-md-6 botao">
            <button type="submit" class="btn btn-primary form-control" name="button" id="button">Salvar</button>
        </div>
        <div class="col-md-6 botao" >
            <button type="button" name="button" id="button" class="btn btn-danger form-control">Cancelar</button>
        </div>

Follow the script:

<script>
    var retorna = function () {
        window.location = "a_pagina_anterior.php";
    }

    var button = document.querySelector("#button"); 
    button.onclick = retorna;
</script>
    
asked by anonymous 13.06.2017 / 13:52

2 answers

1

Answering your question, it leaves the page because you are using

window.location

Explanation:

The window.location object can be used to get the address of the current page (URL) and to redirect the browser to a new page.

    
13.06.2017 / 14:50
0

You need to use window.open and configure it according to your needs:

<script>
 var windowObjectReference;
 var strWindowFeatures ="menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

 var retorna = function () {
    windowObjectReference = window.open("a_pagina_anterior.php", "_blank ", strWindowFeatures);
}

var button = document.querySelector("#button"); 
button.onclick = retorna;

The second window.open parameter is the way it will go:

_blank - O link abrirá em uma nova janela
_self - O link abrirá no mesmo frame onde foi clicado
_parent - O link abrirá no frameset pai
_top - O link abrirá na mesma janela, sem frames

The variable strWindowFeatures refers to the settings of the new window: for details: Window.open

    
13.06.2017 / 15:41