Know what was clicked by the user method confirm

1

I have the following instruction with which my pretensions are to indicate to a user if he wants or not to print a report.

in case it is True print and in case it is false redirects only

 Response.Write("<script lengue>confirm('¿Desea Imprimir Este informe?')</script>"); 

my question is how can I know the option that the user has made

My project is in c #, but I use some JS events

Response.Write("<script lengue>var resultado = confirm('¿Desea Imprimir Este informe?')</script>");

if it was incorporated in that way, how do I access the result variable from outside the script?

    
asked by Andrex_11 07.11.2018 в 22:21
source

3 answers

0

I have managed to do what I required using the following technique

Response.Write("<script language=javascript>");
Response.Write("if(confirm('¿Desea Imprimir Este informe?')){window.location.href='../Visor/ConstruirReporte.aspx?Reporte=CRE9&id=" + TextBoxRecibo.Text + "'}");
Response.Write("</script>");

I do not know if it's the most feasible or ideal, but I've managed to do it that way

    
answered by 08.11.2018 / 20:11
source
4

The confirm function returns a value true (OK) or false (Cancel)

var resultado = confirm('¿Sí o No?');

console.log(resultado);
    
answered by 07.11.2018 в 22:26
1

I show you an example with only JavaScript, I run jQuery to find the download path, once the path is obtained I execute the window.location.href and download the file

if (confirm('¿Desea Imprimir Este informe?')){
		$.ajax({
		
			url : 'https://api.chucknorris.io/jokes/random',
			type : 'GET',
			dataType:'json',
			success : function(data) {
				console.log("retornara el path para descargar");
				window.location.href ="https://legacy.gitbook.com/download/pdf/book/danielmoralesp/javascript-avanzado-en-espanol"
		
			},
			error : function(request,error)
			{
				alert("Request: "+JSON.stringify(request));
			}
		
		
		})
	}else{
     window.location.href ="https://es.stackoverflow.com/users/28035/jacknavarow"
  }
Este ejemplo usa jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
answered by 08.11.2018 в 20:26