Alexandre Alexandre - 2 months ago 7
Javascript Question

How can I go to a new page from within javascript?

I have a link like this:

<a href="www.example.com">


I would like to simulate the clicking of this link within javascript with a function that is called with the left arrow but I am not sure how to do it.

Now I have this:

$(window).keypress(function (e)
{
if (e.keyCode == 37)
{
// position 1
}

});


But I am not sure how to change the page to the link "www.example.com" from within javascript at position 1. Can someone help me with this.

Answer

You could use the following to perform a redirect:

window.location.href = 'www.example.com';
Comments