[英]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. 但是,由于我已经研究了一段时间,所以我想使用这种方法。
What language mix is this? 这是什么语言的组合?
The easiest way to go about this using plain vanilla javascript is something like this: 使用普通香草javascript进行此操作的最简单方法是这样的:
var button = document.getElementById("Sailthru");
button.addEventListener("click", function(){
document.location.href = 'http://www.sailthru.com';
});
Alternatively, this uses HTTP redirects. 或者,这使用HTTP重定向。
HTML HTML
<button id="btn">
Click
</button>
JS JS
btn.onclick = function() {
window.location.replace("http://www.sailthru.com/");
}
you can try 你可以试试
window.open or window.location based on your demand window.open或window.location根据您的需求
window.open(' http://test.com ','_blank'); window.open(' http ://test.com','_ blank');
window.location="http://test.com"; window.location =“ http://test.com”;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.