一直在尝试找到一些解决方案,但我无法找到。我需要一个按钮来一次点击触发两个事件。此代码适用于 Firefox,但不适用于 Chrome:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>EXAMPLE</title>
<script type="text/javascript">
function changeLocation (){
window.location = "https://www.bing.com";
}
</script>
</head>
<body>
<form action="https://www.google.com" target="_blank">
<input type="text">
<button onclick="changeLocation()">Submit</button>
</form>
</body>
</html>
我正在尝试将用户重定向到新选项卡中的新页面,并在单击按钮后重定向主页(旧页面)。 是否有任何解决方案也适用于 Chrome?
非常感谢任何帮助!
最佳答案
function changeLocation() {
document.getElementById("form").submit();
window.open("https://www.bing.com","_blank");
}
<form id="form" action="https://www.google.com">
<input type="text">
<button onclick="changeLocation()">Submit</button>
</form>
这对你有帮助。顺便说一句,您需要使用输入标签中的名称属性来提交数据。
关于javascript - 如何: On click open new page in new tab and redirect the old one,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48973131/