通过确认重定向页面

Redirecting pages with confirmation

本文关键字:重定向 确认      更新时间:2023-09-26

我为我的Web项目做了一个小网站,但我无法让代码工作。我有 4 个"页面"(不知道该怎么称呼它们),我想将它们相互链接。您回答了一个问题,系统会显示一条警报,将您重定向到下一页。我得到了第一个工作链接,但没有其他链接。

这是我的代码:

<button data-href="../index.html" onclick="return confirm_alert(this);" class="knap3" >Nej</button>

这是我用于第一个链接的内容,但是当我有多个链接时,它不起作用。我尝试给他们不同的标签/名称,但这不起作用。

function confirm_alert(element) {
redirect = confirm("confirmation for redirecting?");
if(redirect) {
  window.location = element.dataset.href
}

编辑:当我在我的按钮中放置多个按钮时,它不再起作用(当我单击它们时没有任何反应)。

(英语不是我的母语,所以很抱歉所有的拼写错误。

这是有效的代码

<button onclick="return confirm_alert('../index.html');" class="knap3" >Nej</button>

function confirm_alert(next) {
var msg="confirmation for redirecting?";
if(confirm(msg)) {
   location.href=next;
}
}

这是一个可以工作的独立页面(我测试过它),只需保存它进行测试.html然后尝试一下。如果这有效,您可以开始构建它。如果没有,您有一个单独的问题,我无法提供帮助

<button onclick="return confirm_alert('../index.html');" class="knap3" >Nej</button>
<script>
function confirm_alert(next) {
    var msg="confirmation for redirecting?";
    if(confirm(msg)) {
       location.href=next;
    }
}
</script>