Adding an onclick function to go to url in JavaScript?

Try

 window.location = url;

Also use

 window.open(url);

if you want to open in a new window.


Simply use this

onclick="location.href='pageurl.html';"

In jquery to send a user to a different URL you can do it like this:

$("a#thing_to_click").on('click', function(){
     window.location = "http://www.google.com/";    
});

this way will work too but the above is the newer more correct way to do it these days

$("a#thing_to_click").click(function(e){
         e.preventDefault();
         window.location = "http://www.google.com/";    
});

function URL() {
    location.href = 'http://your.url.here';
}

HTML

<input type="button" value="My Button" 
onclick="location.href = 'https://myurl'" />

MVC

<input type="button" value="My Button" 
onclick="location.href='@Url.Action("MyAction", "MyController", new { id = 1 })'" />