JavaScript 页面跳转前弹窗提示目标 URL
要在页面跳转时执行 alert,并获取要跳转的 url,可以使用以下代码:
<!DOCTYPE html>
<html>
<body>
<script>
// 获取要跳转的 url
function getURL() {
var url = document.getElementById('urlInput').value;
return url;
}
// 页面跳转时执行 alert 并获取 url
function redirectToURL() {
var url = getURL();
alert('即将跳转到:' + url);
window.location.href = url;
}
</script>
<input type="text" id="urlInput" placeholder="输入要跳转的 url">
<button onclick="redirectToURL()">跳转</button>
</body>
</html>
在这个例子中,用户可以在输入框中输入要跳转的 url,然后点击'跳转'按钮。当用户点击按钮时,redirectToURL函数会被调用,它会先调用getURL函数来获取输入框中的 url 值,然后使用alert显示要跳转的 url,并通过window.location.href实现页面跳转。
原文地址: https://www.cveoy.top/t/topic/pkae 著作权归作者所有。请勿转载和采集!