2012-07-20 7 views
6

Ho una funzione javascript. On-clic chiamerà questo. Utilizzo di document.getElementById Qui ottengo determinati parametri. Usando quei parametri ho bisogno di costruire un URL. cioè, onclick dovrà eseguire quell'URL.Chiamare un url in javascript con un clic

Per esempio, in javascript,

function remove() 
{ 
var name=...; 
var age = ...; 
// url should be like http://something.jsp?name=name&age=age 
} 

Insomma ho bisogno di eseguire http://something.jsp?name=name&age=age questo URL al click

<input type="button" name="button" onclick="remove();" /> 

risposta

7

Uso window.location:

function remove() 
{ 
    var name = ...; 
    var age = ...; 

    window.location = 'http://something.jsp?name=' + name + '&age=' + age; 
} 
4

io uso:

document.location.href = "report.html"; 

Quindi, nel tuo caso:

function remove() { 
    var name=... , 
     age = ...; 

    document.location.href = "something.jsp?name=" + name + "&age=" + age; 
} 
Problemi correlati