我有一个问题后,这是我的代码:的Javascript留在网页上点击一个链接
<a href="Webshop.php" class="Button" onclick="myFunction()">Webshop</a>
<script>
function myFunction() {
var r = confirm("If you leave this page your purchase will be gone!");
if (r == true) {
window.location = "http://www.titansafes.sgr15.g-o.be/Webshop.php";
} else {
return
}
}
</script>
如果您按一下按钮,我得到警告,如果他们点击确定,他们直接回网上商店,如果他们点击取消,他们需要留在页面上。但我怎么能做到最好? 我试过Window.location(不工作),返回不起作用,这对我来说很重要。
尝试'返回false'。 – Vinay
然后阅读此:http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false – Vinay