我创建了一个HTML表单来向HipChat发送消息,然而,当我点击提交按钮时,它会不断打开一个新标签,说明它是从HipChat发送的。我怎么能防止这种情况?我希望它保持在同一页面上,可能会有一个JavaScript弹出窗口告诉他们已发送,没有重定向。
代码:
<html>
<body>
<form id="myForm" action="https://api.hipchat.com/v1/rooms/message" method="post">
<input type="hidden" name="room_id" value="example">
<input type="hidden" name="message_format" value="text">
<input type="hidden" name="from" value="example">
<input type="hidden" name="color" value="red">
<input type="hidden" name="notify" value="1">
<input type="hidden" name="auth_token" value="example">
What is your name?
<br>
<br>
<input type="text" name="message" id="myMessage">
<br>
<br>
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
window.onload = function() {
document.getElementById("myForm").onsubmit = function() {
var msgElement = document.getElementById("myMessage");
var textToSend = '@example' + msgElement.value;
msgElement.value = textToSend;
alert("Alert");
return true;
}
};
</script>
</body>
</html>
&#13;