create an HTML button with Onlick that aslo works as a link?

I have a button that adds a product to a basket - I would like to make the button when clicked add the product to the basket via the onclick script - then redirect to a page trough an a href link or similar. Is this possible?

HTML:

<input type="button" id="pl157821buy" class="actionbutton" value="Köp" onclick="buy(this, 157821, null, 'pl157821qty',null, '/ajax/buy')">

不确定这是最佳实践,但您可以在致电buy()后立即使用window.location.assign("/your/other/page") buy()


你可以使用window.location对象:

function buy(...){
   //your current code
   window.location.href = "http://page to be redirected to";
}
链接地址: http://www.djcxy.com/p/36600.html

上一篇: css / html按钮链接不工作

下一篇: 创建一个与Onlick的HTML按钮,作为一个链接?