Refresh a window when I close another

Asked

Viewed 93 times

-1

I have a page with a list of photos. When the user clicks on "add photos", another tab opens in which the user can add photos. But at the end of inserting them, this tab is closed. What I wanted, was to close the window, where I add the photos to the list window Update the list of photos automatically. It is possible?

  • 3

    We need more information... are the photos recorded in a directory? or just a reference on the client side? Do you have any ajax? What is the code like?

  • no, it’s all stored with jquery. What I want is that by clicking "Close window", the listing window can update itself

  • 2

    There are many ways to do this, you need to post some parts of your code, and/or further detail the question, so someone can guide you clearly.

2 answers

1

There is a lot of detail missing from your question. I will respond in a relaxed way with the hope that it will help you.

My suggestion:

HTML

<div id="conteudoJanela">
    <div>Adicione um url aqui:
        <input id="urlImagem" type="text" />
        <br />Exemplo: http://goo.gl/6I4zTg</div>
    <hr />
    <button type="button">Enviar</button>
</div>
<button type="button" id="abrir">Abrir nova janela</button>
<hr/>Lista de URL's
<div id="listaURL"></div>

javascript/jQuery

var conteudo = $('#conteudoJanela').html();

$('#abrir').on('click', function () {
    var win = window.open("", "", "width=400, height=200");
    $novaJanela = $(win.document.body);
    $novaJanela.html(conteudo);
    $novaJanela.find('#enviar').on('click', function () {
        var url = $novaJanela.find('#urlImagem').val();
        $('#listaURL').append(url + '<br />');
        win.close();
    });
});

CSS

#conteudoJanela {
    display: none;
}

Example

0

Test using this method

function closeCallback() {
    //your code here
}

var openTab = function(uri, name, options, closeCallback) {
    var win = window.open(uri, name, options);
    var interval = window.setInterval(function() {
        try {
            if (win == null || win.closed) {
                window.clearInterval(interval);
                closeCallback(win);
            }
        }
        catch (e) {
        }
    }, 1000);
    return win;
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.