Calling url in javascript on click

I have a javascript function. This click will trigger it. Using document.getElementById , I get certain parameters. Using these parameters, I need to create a url. those. onclick will have to execute this url.

For example, in javascript,

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

In short, I need to do http://something.jsp?name=name&age=age this url when clicked

 <input type="button" name="button" onclick="remove();" /> 
+6
source share
3 answers

Use window.location :

 function remove() { var name = ...; var age = ...; window.location = 'http://something.jsp?name=' + name + '&age=' + age; } 
+7
source

I use:

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

So in your case:

 function remove() { var name=... , age = ...; document.location.href = "something.jsp?name=" + name + "&age=" + age; } 
+4
source

just call

 window.location=myURL; 

in your function

+3
source

Source: https://habr.com/ru/post/920955/


All Articles