简体   繁体   English

如何使用addEventListener使按钮将页面重定向到另一个页面?

[英]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.

相关问题 如何使用控制器动作使按钮将页面重定向到另一个页面,并使用javascript传递值? - How can I make a button redirect my page to another page using a controller action and passing a value using javascript? 如何让按钮将我的页面重定向到另一个页面(取决于输入) - How can I make a button redirect my page to another page (depending on the input) 如何在我的网站中将此按钮重定向到网站上的另一个页面? - How can I make this button in my website redirect to another page on the website? 我需要让我的按钮重定向到另一个页面(js文件) - I need to make my button redirect to another page(js file) 我无法在 javascript 上设置计时器以重定向到另一个页面 - I can't make my timer on javascript to redirect to another page 如何使用 jQuery 或仅使用 Javascript 将按钮重定向到另一个页面 - How to make a button redirect to another page using jQuery or just Javascript 如何在React中将按钮重定向到另一个页面 - How to make a button redirect to another page in React 如何将图像制作为按钮并将其重定向到另一个页面? - How to make an image as a button and redirect it to another page? 在 WordPress 中,我如何按下按钮并将所有当前访问者重定向到另一个页面? - In WordPress, how can I push a button and redirect all my current visitors to another page? 检查电子邮件输入验证后,如何使用我的按钮将用户重定向到另一个HTML页面? - How do I redirect the user to another HTML page using my button after checking for email input validation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM