Is it possible to download the link page displayed in the onclick input?

Asked

Viewed 22 times

-1

This is the div with the input that displays the link!

<div>
<input type="text" class="mb-5 form-control" id="linkIn" readonly>
<button type="button" class="btn btn-primary" onclick="copiar()">Copiar</button>
<button type="button" class="btn btn-primary" onclick="baixar()">Baixar</button>
</div>

This the script

<script>

$("#obterLinkdaLista").on('hidden.bs.modal', function (e) {
    $(".select-users").empty();
});

function obterListaUsuarios(id) {
    $('#idLista').val(id);
    $.ajax({
        type: "POST",
        url: "controles/obter-lista-usuarios.php",
        data: {id: id},
        dataType:"json",
        success: function(data) {
            var $select = $('<select/>', {
                'class':"selectpicker",
                'title':"Usuário...",
                'name': "idUsuario"
            });
            for (j=0; j < data.length; j++) {
                $select.append('<option value=' + data[j].id_usuario + '>' + data[j].nome_usuario +     '</option>');
            }
            $select.appendTo('.select-users').selectpicker('refresh');
        }
    });
    $('#obterLinkdaLista').modal();
}

function listaGlobal() {
    $('#cadastro').modal('hide');
    $('#cadastroGlobal').modal();
}

function removerConfirma(id,nome) {
    $('#remover-conteudo').html('<div class="alert alert-danger" role="alert"><strong> Remover </strong>' + nome + '?</div><button onclick="remover(' + id + ')" type="submit" class="btn btn-danger float-right">Remover</button>');
    $('#remover').modal();
}

function editarGlobalConfirma(id,nome, lista) {
    $('#idGE').val(id);
    $('#nomeGE').val(nome);
    $('#nomeGE').val(nome);
    $('#categoriaGE').val(lista);
    $('#categoriaGE').selectpicker('render');
    $('#editarGlobal').modal();
}

function remover(id) {
    $.ajax({
        type: "POST",
        url: "controles/remover-lista.php",
        data: {id: id},
        success: function(data) {
          location.reload();
        }
    });
}

$( "#cadastro-form-global" ).submit(function( event ) {
    $.ajax({
        type: "POST",
        url: "controles/adicionar-lista-global.php",
        data: $("#cadastro-form-global").serialize(),
        success: function(data) {
          location.reload();
        },
        error: function(data) {
          resultado(data.responseText);
        }
    });
    event.preventDefault();
});

$( "#editar-form-global" ).submit(function( event ) {
    $.ajax({
        type: "POST",
        url: "controles/editar-lista-global.php",
        data: $("#editar-form-global").serialize(),
        success: function(data) {
            location.reload();
        },
        error: function(data) {
          resultado(data.responseText);
        }
    });
    event.preventDefault();
});

$( "#formObterLinkdaLista" ).submit(function( event ) {
    $.ajax({
        type: "POST",
        url: "controles/obter-link-lista.php",
        data: $("#formObterLinkdaLista").serialize(),
        success: function(data) {
            $('#linkIn').val(data);
            $('#obterLinkdaLista').modal('hide');
            $('#linkLista').modal();
        }
    });
    event.preventDefault();
});

function copiar() {
    $('#linkIn').select();
    document.execCommand("copy");
}

</script>

The function

function copiar() {
    $('#linkIn').select();
    document.execCommand("copy");
}

It is responsible for copying the input link, the doubt would be the correct way to add the button to download what is in the link that the input shows.

1 answer

0

As you demonstrate that answer, you can use a function that adds the link, with the URL that contains the file to download, in the body of your page, and then click this link programmatically.

Or, you can use the download js..

  • The link is not static, it changes every time you access the page where the input is, I have the button that copies the link shown so that I open in the browser, and download the page. but wanted to remove these copy and paste steps by adding a download button.

  • I made this change in the Download button, now it is opening in a new tab, has a way to download this page without opening in new tab? <button type="button" class="btn btn-Primary" onclick="javascript: window.open(Document.getElementById('Linkin').value);">Download</button>

Browser other questions tagged

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