Darren Blair
Darren Blair

Reputation: 21

How can I make a button redirect my page to another page using addEventListener?

Currently after searching the internet I've come up with this code:

function button(){


        var button= getElementById("Sailthru");

    button.addEventListener(MouseEvent.CLICK, onClick, false, 0, true)
  function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.sailthru.com/"), "_blank");
};

Though it doesn't work, and I am unsure how to proceed. If there are no ways to make it work using this, then I will happily use another method. However I would like to use this method since I've been working on this for a while.

Upvotes: 2

Views: 10656

Answers (3)

Hadi Ranjbar
Hadi Ranjbar

Reputation: 1812

you can try

window.open or window.location based on your demand

window.open('http://test.com','_blank');

window.location="http://test.com";

Upvotes: 0

Charles Clayton
Charles Clayton

Reputation: 17966

Alternatively, this uses HTTP redirects.

HTML

<button id="btn">
  Click
</button>

JS

btn.onclick = function() {
  window.location.replace("http://www.sailthru.com/");
}

Upvotes: 1

HaukurHaf
HaukurHaf

Reputation: 13816

What language mix is this?

The easiest way to go about this using plain vanilla javascript is something like this:

var button = document.getElementById("Sailthru");

button.addEventListener("click", function(){
    document.location.href = 'http://www.sailthru.com';
});

Upvotes: 5

Related Questions